[SNMP4J] NullPointerException in processReport()

Frank Fock fock at agentpp.com
Sat Aug 2 08:12:52 CEST 2008


Hi Chris,

Yes, this seems to be a regression in the last version. Your
workaround is OK and will be part of the next version.

Best regards,
Frank

Christian Defoy schrieb:
> Hi,
>
> I am receiving a NullPointerException using SNMPv3 at AuthPriv level.
> It is worth mentioning that I am using localized users.  The error
> occurs when I am deliberately using a wrong authentication password:
>
>         snmp.getUSM().addLocalizedUser( engineID, new OctetString(
> "admin" ), AuthMD5.ID, security.passwordToKey( AuthMD5.ID, new
> OctetString( "wrong" ), engineID ), PrivDES.ID,
> security.passwordToKey( PrivDES.ID, AuthMD5.ID, new OctetString(
> "password" ), engineID ) );
>
> I have located the source of the problem in the Snmp$ReportProcessor
> class in the processReport() method.
>
> // if legal report PDU received, then resend request
> if( resend )
> {
>    logger.debug( "Send new request after report." );
>    ...
> }
> else
> {
>    boolean intime;
>    synchronized( request )
>    {
>       intime = request.cancel();  // This here sets request.listener = null
>    }
>    // remove pending request
>    // (sync is not needed as request is already canceled)
>    pendingRequests.remove( handle );
>    if( intime )
>    {
>       // return report
>       request.listener.onResponse( new ResponseEvent( this,
> e.getPeerAddress(), request.pdu, pdu, request.userObject ) );
>       // BOOM!
>
> The call to request.cancel() sets the request.listener to null.
> Later, if the response in intime, a call to
> request.listener.onResponse is made.  That's where it hurts!  The
> worker thread never returns and the caller never gets notified that a
> problem occured.  Am I understanding this correctly?  Is it possible
> that I am doing something wrong?
>
> Just for fun, I tried the following fix and it seems to work but my
> knowledge of SNMPv3 security is not really good so I may be breaking
> something.
>
> Possible fix: retrieve a reference to the listener in the synchronized
> block prior to invoking the cancel() method.  Since the reportHandler
> is pluggable in the Snmp class, it might be a good idea to wrap its
> invocation with a try-catch block :)
> _______________________________________________
> SNMP4J mailing list
> SNMP4J at agentpp.org
> http://lists.agentpp.org/mailman/listinfo/snmp4j
>   




More information about the SNMP4J mailing list