sfbpf_realloc() question

Bill Parker <[email protected]>
Newsgroups gmane.comp.security.ids.snort.devel
Message-ID <CAFrbyQzs6TiKeEBCKVEpp4=OPfMf247FS4b3UD3_KBcGy3tggA@mail.gmail.com>
Hello All,

    In reviewing code in snort-2.9.x, where calls to sfbpf_realloc() are
made, as below, if realloc() fails, it returns a NULL value, which will
clobber what YY_CURRENT_BUFFER_LVALUE->yy_ch_buf points to (which would be
NULL), but according to the C9x standard, when realloc() returns NULL, the
original buffer is unchaged.

Shouldn't a temporary variable be used to keep track of the above memory
location, in the event sfbpf_realloc() fails?  (unless YY_FATAL_ERROR
causes DAQ to terminate?):

{
                /* Extend the array by 50%, plus the number we really need.
*/
                yy_size_t new_size = (yy_n_chars) + number_to_move +
((yy_n_chars) >> 1);
                YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *)
sfbpf_realloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size  );
                if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
                        YY_FATAL_ERROR( "out of dynamic memory in
yy_get_next_buffer()" );
        }

        (yy_n_chars) += number_to_move;

Bill

------------------------------------------------------------------------------

_______________________________________________
Snort-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/snort-devel
Archive:
http://sourceforge.net/mailarchive/forum.php?forum_name=snort-devel

Please visit http://blog.snort.org for the latest news about Snort!
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.