[BusyBox] skip_whitespace.c can segfault
Tito
farmatito at tiscali.it
Wed Mar 17 16:18:22 UTC 2004
Hi to all,
I noticed that the bb_skip_whitespace() function can
segfault if the argument passed is NULL as can
easily be demonstrated by this example:
#include <ctype.h>
#include <stdio.h>
/*#include "libbb.h"*/
extern const char *bb_skip_whitespace(const char *s)
{
while ( isspace(*s)) {
++s;
}
return s;
}
int main(int argc, char **argv)
{
bb_skip_whitespace(NULL);
return 0;
}
root at localhost:/dev/pts/1:/rep/busybox-1.00-pre8/libbb# ./test
Segmentation fault (core dumped)
I can't say if this is a treat for an experienced programmer,
but it could be fixed by modifying *bb_skip_whitespace(const char *s) to
extern const char *bb_skip_whitespace(const char *s)
{
while ( s && isspace(*s)) {
++s;
}
return s;
}
the increase in size is not so much:
root at localhost:/dev/pts/1:/rep/busybox-1.00-pre8/libbb# size skip_whitespace.o
text data bss dec hex filename
29 0 0 29 1d skip_whitespace.o
root at localhost:/dev/pts/1:/rep/busybox-1.00-pre8/libbb# size skip_whitespace.o
text data bss dec hex filename
33 0 0 33 21 skip_whitespace.o
root at localhost:/dev/pts/1:/rep/busybox-1.00-pre8/libbb#
The gurus will know whether it is worth to fix it or not. ;-)
Ciao,
Tito
More information about the busybox
mailing list