Thank you very much, it works fine.
MF
-----Original Message-----
From: Magnus Fromreide [mailto:ma...@lysator.liu.se]
Sent: giovedì 5 gennaio 2017 18:34
To: Moreno Floris <moreno.flo...@telit.com>;
net-snmp-coders@lists.sourceforge.net
Subject: Re: Proposed fix for mib.c
On Thu, Jan 05, 2017 at 02:21:42PM +0000, Moreno Floris wrote:
> 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.
I am not happy about more global variables so I have this alternate patch where
I move the variable 'buffer' to another function that I call from
_get_realloc_symbol when it is needed.
This has the advantage of no global variables (yay - thread safety) and only
creating the variable when it is used.
Does this version also wok for you?
/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