volsung@asu.edu
2000-Jun-19 07:58 UTC
[vorbis-dev] PATCH: Falling off the end of linked lists.
[I'm still poking around in vorbis-tools. Here's another trivial patch.] In ogg123.c, the function get_stream goes down a linked list looking for the nth stream. Currently it will run off the end of the list and dereference the NULL pointer if the list is smaller than n. Attached is a patch to check for a null list and abort. Would assert() be a better way to do this? -=-=- Stan Seibert Index: vorbis-tools/ogg123.c ==================================================================RCS file: /usr/local/cvsroot/vorbis/vorbis-tools/ogg123.c,v retrieving revision 1.1 diff -u -r1.1 ogg123.c --- vorbis-tools/ogg123.c 2000/06/14 23:07:47 1.1 +++ vorbis-tools/ogg123.c 2000/06/19 14:44:16 @@ -104,20 +104,28 @@ FILE * get_stream (int num, struct streams * streams_list) { - if (num < 0) + if (streams_list != NULL) { - fprintf (stderr, "Internal error: get_stream called with a negative argument.\n"); - exit (1); + if (num < 0) + { + fprintf (stderr, "Internal error: get_stream called with a negative argument.\n"); + exit (1); + } + else + if (num == 0) + { + return streams_list->stream; + } + else + { + return get_stream ( num--, streams_list->next_stream ); + } } else - if (num == 0) - { - return streams_list->stream; - } - else - { - return get_stream ( num--, streams_list->next_stream ); - } + { + fprintf (stderr, "Internal error: get_stream called with NULL stream_list.\n"); + exit (1); + } } void usage () --- >8 ---- List archives: http://www.xiph.org/archives/ Ogg project homepage: http://www.xiph.org/ogg/
Kenneth C. Arnold
2000-Jun-19 08:16 UTC
[vorbis-dev] PATCH: Falling off the end of linked lists.
On Mon, Jun 19, 2000 at 07:58:43AM -0700, volsung@asu.edu wrote:> [I'm still poking around in vorbis-tools. Here's another trivial patch.] > > In ogg123.c, the function get_stream goes down a linked list looking for the > nth stream. Currently it will run off the end of the list and dereference the > NULL pointer if the list is smaller than n. Attached is a patch to check for > a null list and abort.Just as soon as I figure out how to commit stuff ... that function gets an #if 0 around it, because it is replaced by a function with a slightly different purpose (to make buffering easier when I get to that). I don't think the new function has such bugs. Kenneth --- >8 ---- List archives: http://www.xiph.org/archives/ Ogg project homepage: http://www.xiph.org/ogg/