diff options
author | Eric Andersen <andersen@codepoet.org> | 2001-04-03 22:50:52 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2001-04-03 22:50:52 +0000 |
commit | 60b2d8d2c8bf9e1bb3f34a3b16b272c2539a6318 (patch) | |
tree | 28a3e4396e8b8c69b51c793fb16198002272f894 | |
parent | c97ec34370f66771713809ab7da19b7fe923cffe (diff) | |
download | busybox-w32-60b2d8d2c8bf9e1bb3f34a3b16b272c2539a6318.tar.gz busybox-w32-60b2d8d2c8bf9e1bb3f34a3b16b272c2539a6318.tar.bz2 busybox-w32-60b2d8d2c8bf9e1bb3f34a3b16b272c2539a6318.zip |
if strlen(s) was 0, it would then end up using s[-1] as an array index. Bad,
bad, bad. This was crashing the shell on powerpc boxes, though all other archs
seem to have a much more forgiving malloc implementations. I finally found
this bug using electric-fence on a powerpc box.
-Erik
-rw-r--r-- | libbb/trim.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/libbb/trim.c b/libbb/trim.c index 8a9b07a14..be97d4924 100644 --- a/libbb/trim.c +++ b/libbb/trim.c | |||
@@ -33,13 +33,14 @@ | |||
33 | 33 | ||
34 | void trim(char *s) | 34 | void trim(char *s) |
35 | { | 35 | { |
36 | int len; | ||
37 | |||
36 | /* trim trailing whitespace */ | 38 | /* trim trailing whitespace */ |
37 | while (isspace(s[strlen(s)-1])) | 39 | while ( (len=strlen(s)) >= 1 && isspace(s[len-1])) |
38 | s[strlen(s)-1]='\0'; | 40 | s[len-1]='\0'; |
39 | 41 | ||
40 | /* trim leading whitespace */ | 42 | /* trim leading whitespace */ |
41 | memmove(s, &s[strspn(s, " \n\r\t\v")], strlen(s)); | 43 | memmove(s, &s[strspn(s, " \n\r\t\v")], len); |
42 | |||
43 | } | 44 | } |
44 | 45 | ||
45 | /* END CODE */ | 46 | /* END CODE */ |