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") )
|
!strcmp(apDescriptor->pProtocol->pVariables[i]->pValueString, "Unknown") )
|
||||||
{
|
{
|
||||||
/* Store the new value if it's valid */
|
/* 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 */
|
int j; /* Loop counter */
|
||||||
|
|
||||||
for ( j = 0; j < VariableNameTable[i].Max && *apValue != '\0'; ++apValue )
|
if ( pBuffer != NULL )
|
||||||
{
|
{
|
||||||
if ( isprint(*apValue) )
|
for ( j = 0; j < VariableNameTable[i].Max && *apValue != '\0'; ++apValue )
|
||||||
pBuffer[j++] = *apValue;
|
{
|
||||||
}
|
if ( isprint(*apValue) )
|
||||||
pBuffer[j++] = '\0';
|
pBuffer[j++] = *apValue;
|
||||||
|
}
|
||||||
|
pBuffer[j++] = '\0';
|
||||||
|
|
||||||
if ( j >= VariableNameTable[i].Min )
|
if ( j >= VariableNameTable[i].Min )
|
||||||
{
|
{
|
||||||
free(apDescriptor->pProtocol->pVariables[i]->pValueString);
|
free(apDescriptor->pProtocol->pVariables[i]->pValueString);
|
||||||
apDescriptor->pProtocol->pVariables[i]->pValueString = AllocString(pBuffer);
|
apDescriptor->pProtocol->pVariables[i]->pValueString = AllocString(pBuffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
free(pBuffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user