diff options
author | Stef Walter <stef@memberwebs.com> | 2010-12-08 16:25:35 +0000 |
---|---|---|
committer | Stef Walter <stef@memberwebs.com> | 2010-12-08 16:25:35 +0000 |
commit | e9e15ea90366b9a07bc7493ea3398a426b176546 (patch) | |
tree | af8db552f0ec1d043e1f526b14e582d938aaa2d9 | |
parent | 4f7092b6369c8c1cdaba0a4aa8c6e4fc6f103423 (diff) |
Fix problems with rollover of snmp ids overflowing integers.
-rw-r--r-- | common/snmp-engine.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/common/snmp-engine.c b/common/snmp-engine.c index 1c29320..5078d39 100644 --- a/common/snmp-engine.c +++ b/common/snmp-engine.c @@ -387,6 +387,8 @@ struct socket struct socket *next; /* Linked list of socket structures */ }; +#define MAX_SNMP_REQUEST_ID 0x800000 + /* The number of SNMP packet retries */ static int snmp_retries = 3; @@ -805,10 +807,14 @@ request_prep_instance (struct host *host, mstime interval, mstime timeout, int r } /* Assign the unique id */ - req->snmp_id = snmp_request_id++; + req->snmp_id = ++snmp_request_id; - /* Roll around after a decent amount of ids */ - if (snmp_request_id >= 0xFFFFFF) + /* + * Roll around after a decent amount of ids. Since we're using + * signed integers, and these are used in strange ways, we can't + * go above 0x800000 or so. + */ + if (snmp_request_id >= MAX_SNMP_REQUEST_ID) snmp_request_id = 1; /* Mark it down as something we want to prepare */ @@ -904,7 +910,7 @@ snmp_engine_cancel (int id) snmp_id = REQUEST_ID_SNMP (id); callback_id = REQUEST_ID_CB (id); - ASSERT (snmp_id > 0 && snmp_id < 0xFFFFFF); + ASSERT (snmp_id > 0 && snmp_id < MAX_SNMP_REQUEST_ID); ASSERT (callback_id >= 0 && callback_id < SNMP_MAX_BINDINGS); /* Is it being processed? */ |