Hi Phil.

Gillis, Philip W (Philip) wrote:

In 5.2 win32, my snmp commands now crash, quite early on.

What version of Windows and MSVC are you using?

I tracked it to netsnmp_getenv() in libsnmp\tools.c. First, it sets temp = getenv(name), then looks in the registry if name was not found in the registry. Then it calls setenv(temp) to set it from now on. Then (here comes the crash), it calls SNMP_FREE(temp). If temp was found in the environment first (not the registry), this crashes. On the second call for the same variable, it will certainly be found in the environment, and we crash.

What you suggest makes sense. Getenv on both Windows and Linux returns a pointer to the variable in the environment space. It's not a copy of it, it's a pointer to the enviornment variable. Freeing this would be a bad idea.


I tested on my system (Windows 2000, MSVC 6) and there is no crash when using either the registry or the environment variable, even when SNMPCONFPATH is loaded multiple times. For my testing I used:

  snmptranslate -Dread_config -IR -Td linkDown

I also tested with a MinGW build before the 5.2 release and I didn't have any problems.

I'm not sure why it's crashing for you but not for me but like I said, your change does seem to make sense. Knowing the version of your Windows etc may help.

Also, I found that when I just download and build the source, and use build.bat, and let it install after building, the registry is not set with the net-SNMP variables. Running win32\install-net-snmp.bat does not help. I had to install the binaries, to get the variables in the environment.

I thought that the README.WIN32 file was updated with that information. I guess it didn't make it in. It's mentioned in the README for the binary (win32/dist/README.txt), which is included in the binary which you installed. I'll fix that for the next release.


Alex



I did a quick fix to tools.c to prevent the freeing of vars returned from getenv():


int got_env = 0; // PWG kludge to avoid freeing temp from getenv()


/* Try environment variable first */

  temp = getenv(name);

  if (temp){

DEBUGMSGTL(("read_config", "netsnmp_getenv will return from ENV: %s\n",temp));

          got_env =1;            // PWG added

  }


  if (temp && !got_env) {             // PWG added !got_env

    setenv(name, temp, 1);

    SNMP_FREE(temp);

}



-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now. http://productguide.itmanagersjournal.com/
_______________________________________________
Net-snmp-coders mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders

Reply via email to