Cleanup of ignored SNMP requests

I am having an issue with an SNMP Agent I created recently using SNMP++/Agent++. I have a customer requirement to perform IP address whitelisting of any SNMP request received by the agent. Essentially, I want to ignore the Snmp request if the IP address is not in the whitelist. The Agent application is crashing occasionally when receiving and ignoring an SNMP request from an unauthorized sender.

Here is a code mockup of what we are currently doing when processing or ignoring the request based on the sender’s IP address being in our whitelist.

Request* req;
while (run) {
req = reqList->receive(2);
if (req) {
if(isRequestIsFromWhitelistedIpAddress(req) == true) {
mib->process_request(req);
}
else {
delete req;
** req = nullptr**;
}
}
else {
mib->cleanup();
}
}

My current operating assumption is that I am NOT supposed to be deleting the req object returned from reqList->receive() function.

What actions should be taken by the agent in the event that a request is to be ignored?
Should I instead be calling
reqList->remove_request(req);
to clean up the requests that are being ignored instead of just deleting the req object?

Here are some additional details from the generated crashdump file.
Call Stack:

Rescue21SnmpAgent.exe!Agentpp::RequestList::find_request_on_id(unsigned long rid) Line 840 C++
Rescue21SnmpAgent.exe!Agentpp::RequestList::add_request(Agentpp::Request * req) Line 1665 C++
Rescue21SnmpAgent.exe!Agentpp::RequestList::receive(int sec) Line 1595 C++

Request* RequestList::find_request_on_id(unsigned long rid)
{
	ListCursor<Request> cur;
	for (cur.init(requests); cur.get(); cur.next()) {
		if (cur.get()->get_pdu()->get_request_id() == rid) { //Receiving unhandled exception executing this line. "Access violation reading location 0x0000001C. "
			return cur.get();
		}
	}
	return 0;
}

Thanks in advance for any assistance and/or feedback you can offer.

Hello,

you should use the following function from RequestList class:

/**
 * Remove a request that should not be processed.
 *
 * @param req - The pointer returned from receive(), the
 *              pointer is invalid after this function returns.
 */
virtual void		remove_request(Request* req);

Kind regards,
Jochen

1 Like