Re: program coredump because "callback_magic" behavior was changed since 5.6.x
Bill Fenner <[email protected]>
| Newsgroups | gmane.network.net-snmp.user |
|---|---|
| Message-ID | <CAF4SogbTwUteovMgLDnwuwOR30W=3ufp37NCs9m-GYW4zGE2Dg@mail.gmail.com> |
Can you try the V5-7-patches branch and see what you experience? I think this is fixed by: commit 56c30b11f3616ea4f0c38a21e08e78f050096020 Author: Bill Fenner <[email protected]> Date: Wed Dec 20 21:52:10 2017 +0000 NEWS: snmplib: PATCH: 1349: Fix perl/other crash against bad SNMPv3 agent With the patch in 1214, the snmp_api code assumed that if magic was set, it was the "struct synch-state" from snmp_client. Of course, magic belongs to the caller, and the perl library uses it differently, so reaching into it is verboten. Introduce a new callback (that was already introduced in 5.8) to report this "retries exceeded" state, and use it in snmp_client. Thanks, Bill On Sat, Jan 13, 2018 at 1:36 AM, Hao Chen <[email protected]> wrote: > Hi All: > > > > 1. > > My program need to use "callback" function and pass something back. > > So, I use "callback_magic" to store an C++ object address. > > So, I can get my C++ object and use it my callback function. > > > > My code looks like: > > ================================ > > bool CERSnmpSession::open() > > { > > ..... > > m_sessionData.callback = callBack; > > m_sessionData.callback_magic = this; > > ..... > > } > > > > int SNMPSession::callBack( > > int operation, > > struct snmp_session *ses, > > int reqid, > > struct snmp_pdu *pdu, > > void* magic) > > { > > SNMPSession* ss = static_cast<SNMPSession*>(magic); > > ..... > > } > > > > > > 2. > > The above code works well with net-snmp 5.4.4. > > But it coredump with net-snmp 5.7.3 while I set correct username & wrong > password to do negative test. > > > > (1). > > The reason is that "_sess_process_packet()" (in snmp_api.c in 5.7.3) does: > > if (callback == NULL > > || callback(NETSNMP_CALLBACK_OP_RECEIVED_MESSAGE, sp, > > pdu->reqid, pdu, magic) == 1) { > > if (pdu->command == SNMP_MSG_REPORT) { > > if (sp->s_snmp_errno == SNMPERR_NOT_IN_TIME_WINDOW || > > snmpv3_get_report_type(pdu) == > > SNMPERR_NOT_IN_TIME_WINDOW) { > > /* > > * trigger immediate retry on recoverable Reports > > * * (notInTimeWindow), incr_retries == TRUE to prevent > > * * inifinite resend > > */ > > if (rp->retries <= sp->retries) { > > snmp_resend_request(slp, rp, TRUE); > > break; > > } else { > > /* We're done with retries, so no longer waiting for > a response */ > > if (magic) { > > ((struct synch_state*)magic)->waiting = 0; > > } > > } > > } else { > > if (SNMPV3_IGNORE_UNAUTH_REPORTS) { > > break; > > } else { /* Set the state to no longer be waiting, > since we're done with retries */ > > if (magic) { > > ((struct synch_state*)magic)->waiting = 0; ====> > culprit > > } > > > > > > (2). > > I compared the same code in 5.4.4, it is: > > if (callback == NULL > > || callback(NETSNMP_CALLBACK_OP_RECEIVED_MESSAGE, sp, > > pdu->reqid, pdu, magic) == 1) { > > if (pdu->command == SNMP_MSG_REPORT) { > > if (sp->s_snmp_errno == SNMPERR_NOT_IN_TIME_WINDOW || > > snmpv3_get_report_type(pdu) == > > SNMPERR_NOT_IN_TIME_WINDOW) { > > /* > > * trigger immediate retry on recoverable Reports > > * * (notInTimeWindow), incr_retries == TRUE to prevent > > * * inifinite resend > > */ > > if (rp->retries <= sp->retries) { > > snmp_resend_request(slp, rp, TRUE); > > break; > > } > > } else { > > if (SNMPV3_IGNORE_UNAUTH_REPORTS) { > > break; > > } > > } > > > > > > (3). > > We can see 5.7.3 has extra "((struct synch_state*)magic)->waiting = 0;" > than 5.4.4 > > > > 3. > > Can you please help me: > > 1). If I want to pass private stuff, shall I use "callback_magic" or > "myvoid in struct snmp_session" to contain it? > > I tested by using "myvoid" instead of "callback_magic" to contain my > private call back data. It works fine. > > > > 2). Since "callback_magic" was changed since net-snmp 5.6.x, will net-snmp > change "myvoid" in future release? > > > > > > > > Thanks and regards > > > ------------------------------------------------------------ > ------------------ > Check out the vibrant tech community on one of the world's most > engaging tech sites, Slashdot.org! http://sdm.link/slashdot > _______________________________________________ > Net-snmp-users mailing list > [email protected] > Please see the following page to unsubscribe or change other options: > https://lists.sourceforge.net/lists/listinfo/net-snmp-users > > ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ Net-snmp-users mailing list [email protected] Please see the following page to unsubscribe or change other options: https://lists.sourceforge.net/lists/listinfo/net-snmp-users