mirror of
https://github.com/tbamud/tbamud.git
synced 2026-04-30 04:41:51 +02:00
Potential fix for code scanning alert no. 55: Call to alloca in a loop (#175)
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
This commit is contained in:
@@ -2102,20 +2102,25 @@ static void ExecuteMSDPPair( descriptor_t *apDescriptor, const char *apVariable,
|
||||
!strcmp(apDescriptor->pProtocol->pVariables[i]->pValueString, "Unknown") )
|
||||
{
|
||||
/* Store the new value if it's valid */
|
||||
char *pBuffer = alloca(VariableNameTable[i].Max+1);
|
||||
char *pBuffer = malloc(VariableNameTable[i].Max + 1);
|
||||
int j; /* Loop counter */
|
||||
|
||||
for ( j = 0; j < VariableNameTable[i].Max && *apValue != '\0'; ++apValue )
|
||||
if ( pBuffer != NULL )
|
||||
{
|
||||
if ( isprint(*apValue) )
|
||||
pBuffer[j++] = *apValue;
|
||||
}
|
||||
pBuffer[j++] = '\0';
|
||||
for ( j = 0; j < VariableNameTable[i].Max && *apValue != '\0'; ++apValue )
|
||||
{
|
||||
if ( isprint(*apValue) )
|
||||
pBuffer[j++] = *apValue;
|
||||
}
|
||||
pBuffer[j++] = '\0';
|
||||
|
||||
if ( j >= VariableNameTable[i].Min )
|
||||
{
|
||||
free(apDescriptor->pProtocol->pVariables[i]->pValueString);
|
||||
apDescriptor->pProtocol->pVariables[i]->pValueString = AllocString(pBuffer);
|
||||
if ( j >= VariableNameTable[i].Min )
|
||||
{
|
||||
free(apDescriptor->pProtocol->pVariables[i]->pValueString);
|
||||
apDescriptor->pProtocol->pVariables[i]->pValueString = AllocString(pBuffer);
|
||||
}
|
||||
|
||||
free(pBuffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user