Skip to content

Commit

Permalink
agent: helpers: added allocation fail check
Browse files Browse the repository at this point in the history
Fixes: e2ea345(Agent helper module for support of scalar objects.)

Found by RASU JSC

Signed-off-by: Maxim Korotkov <[email protected]>
  • Loading branch information
ProjectMutilation committed Dec 19, 2023
1 parent 80a1742 commit 11cfada
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions agent/helpers/scalar.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,19 @@ netsnmp_get_scalar_handler(void)
int
netsnmp_register_scalar(netsnmp_handler_registration *reginfo)
{
netsnmp_mib_handler *h1, *h2;

netsnmp_mib_handler *h1 = NULL, *h2 = NULL;
netsnmp_handler_registration *tmp;
/*
* Extend the registered OID with space for the instance subid
* (but don't extend the length just yet!)
*/
reginfo->rootoid = (oid*)realloc(reginfo->rootoid,

tmp = (oid*)realloc(reginfo->rootoid,
(reginfo->rootoid_len+1) * sizeof(oid) );
if (tmp == NULL) {
goto error;
}
reginfo->rootoid = tmp;
reginfo->rootoid[ reginfo->rootoid_len ] = 0;

h1 = netsnmp_get_instance_handler();
Expand All @@ -98,14 +103,13 @@ netsnmp_register_scalar(netsnmp_handler_registration *reginfo)
return netsnmp_register_serialize(reginfo);
}
}

error:
snmp_log(LOG_ERR, "register scalar failed\n");
netsnmp_handler_free(h1);
netsnmp_handler_free(h2);
netsnmp_handler_registration_free(reginfo);

return MIB_REGISTRATION_FAILED;
}
retu


/**
Expand Down

0 comments on commit 11cfada

Please sign in to comment.