Hello,

I'm running net-snmp 5.7.3 on an embedded platform with 16KB of stack for a 
single task and I ran into a nasty stack overflow while running the coding 
tutorial example.

After some investigation I found out that _get_realloc_symbol() in mib.c is 
called recursively 8 times and contains the following declaration:

u_char          buffer[1024];

This is bad for stack consumption, I renamed it "my_buffer" and declared it 
externally (because I don't have the 16KB limitation for global stack).

Inside the function I replaced the declaration with

memset(&my_buffer,0,sizeof(my_buffer)); 

to make sure it's clean before each use.

I chose a global static over a local dynamic because with all the gotos I 
wouldn't know where to put the free()

After this simple modification, the maximum stack consumption is 78%, still 
high but well within the limit (and my program is not crashing anymore).

Please let me know your opinion on this.

MF
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most 
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Net-snmp-coders mailing list
Net-snmp-coders@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders

Reply via email to