On Sun, Feb 25, 2007 at 11:36:34PM +0800, Moore Michael wrote:
> Hi there
>
> I use net-snmp-5.4, and there's a NULL pointer operator in
> snmplib/snmp_api.c
>
> void *
> snmp_sess_pointer(netsnmp_session * session)
> {
> struct session_list *slp;
>
> snmp_res_lock(MT_LIBRARY_ID, MT_LIB_SESSION);
> for (slp = Sessions; slp!=NULL; slp = slp->next) {
> if (slp->session == session) {
>
> /* ^------------------- here for the loop end, slp=NULL
> then slp->session illegal, or change the for loop to while loop; such as
> while(slp!=NULL) { xxx; slp=slp->next; } */
>
> break;
> }
> }
This code is perfectly valid:
for (slp = Sessions; slp; slp = slp->next) {
if (slp->session == session) {
break;
}
}
is the same as
slp = Sessions; /* initialization part */
while ( slp != NULL ) /* test part */
{
if ( slp->session == session )
break;
slp = slp->next; /* increment part */
}
In particular, the increment is not done until after the slp!=NULL test has been
performed.
Steve
---
Stephen J Friedl | Security Consultant | UNIX Wizard | +1 714 544-6561
www.unixwiz.net | Tustin, Calif. USA | Microsoft MVP | [EMAIL PROTECTED]
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Net-snmp-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders