From 11cfadadbaf75ba253cc57b8ec9a73967bb260e8 Mon Sep 17 00:00:00 2001 From: Maxim Korotkov Date: Tue, 19 Dec 2023 17:44:45 +0300 Subject: [PATCH] agent: helpers: added allocation fail check Fixes: e2ea345fa783(Agent helper module for support of scalar objects.) Found by RASU JSC Signed-off-by: Maxim Korotkov --- agent/helpers/scalar.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/agent/helpers/scalar.c b/agent/helpers/scalar.c index 0278606c68..2bb9432c3b 100644 --- a/agent/helpers/scalar.c +++ b/agent/helpers/scalar.c @@ -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(); @@ -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 /**