Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

snmp: fix dangling pointer in snmp_traps #51

Merged
merged 3 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/apps/snmp/snmp_msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,6 @@ snmp_receive(void *handle, struct pbuf *p, const ip_addr_t *source_ip, u16_t por
struct snmp_varbind vb;

vb.next = NULL;
vb.prev = NULL;
vb.type = SNMP_ASN1_TYPE_COUNTER32;
vb.value_len = sizeof(u32_t);

Expand Down
14 changes: 1 addition & 13 deletions src/apps/snmp/snmp_traps.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,13 +351,11 @@ snmp_send_trap_or_notification_or_inform_generic(struct snmp_msg_trap *trap_msg,
u16_t tot_len = 0;
err_t err = ERR_OK;
u32_t timestamp = 0;
struct snmp_varbind *original_varbinds = varbinds;
struct snmp_varbind *original_prev = NULL;
struct snmp_obj_id snmp_trap_oid = { 0 }; /* used for converting SNMPv1 generic/specific trap parameter to SNMPv2 snmpTrapOID */
struct snmp_varbind snmp_v2_special_varbinds[] = {
/* First varbind is used to store sysUpTime */
{
NULL, /* *next */
NULL, /* *prev */
{ /* oid */
8, /* oid len */
{1, 3, 6, 1, 2, 1, 1, 3} /* oid for sysUpTime */
Expand All @@ -369,7 +367,6 @@ snmp_send_trap_or_notification_or_inform_generic(struct snmp_msg_trap *trap_msg,
/* Second varbind is used to store snmpTrapOID */
{
NULL, /* *next */
NULL, /* *prev */
{ /* oid */
10, /* oid len */
{1, 3, 6, 1, 6, 3, 1, 1, 4, 1} /* oid for snmpTrapOID */
Expand All @@ -383,23 +380,17 @@ snmp_send_trap_or_notification_or_inform_generic(struct snmp_msg_trap *trap_msg,
LWIP_ASSERT_SNMP_LOCKED();

snmp_v2_special_varbinds[0].next = &snmp_v2_special_varbinds[1];
snmp_v2_special_varbinds[1].prev = &snmp_v2_special_varbinds[0];

snmp_v2_special_varbinds[0].value = &timestamp;

snmp_v2_special_varbinds[1].next = varbinds;

/* see rfc3584 */
if (trap_msg->snmp_version == SNMP_VERSION_2c) {
struct snmp_obj_id snmp_trap_oid = { 0 }; /* used for converting SNMPv1 generic/specific trap parameter to SNMPv2 snmpTrapOID */
err = snmp_prepare_trap_oid(&snmp_trap_oid, eoid, generic_trap, specific_trap);
if (err == ERR_OK) {
snmp_v2_special_varbinds[1].value_len = snmp_trap_oid.len * sizeof(snmp_trap_oid.id[0]);
snmp_v2_special_varbinds[1].value = snmp_trap_oid.id;
if (varbinds != NULL) {
original_prev = varbinds->prev;
varbinds->prev = &snmp_v2_special_varbinds[1];
}
varbinds = snmp_v2_special_varbinds; /* After inserting two varbinds at the beginning of the list, make sure that pointer is pointing to the first element */
}
}
Expand All @@ -422,9 +413,6 @@ snmp_send_trap_or_notification_or_inform_generic(struct snmp_msg_trap *trap_msg,
}
}
}
if ((trap_msg->snmp_version == SNMP_VERSION_2c) && (original_varbinds != NULL)) {
original_varbinds->prev = original_prev;
}
req_id++;
return err;
}
Expand Down
2 changes: 0 additions & 2 deletions src/include/lwip/apps/snmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ struct snmp_varbind
{
/** pointer to next varbind, NULL for last in list */
struct snmp_varbind *next;
/** pointer to previous varbind, NULL for first in list */
struct snmp_varbind *prev;

/** object identifier */
struct snmp_obj_id oid;
Expand Down