diff options
author | Rob Landley <rob@landley.net> | 2016-04-14 21:00:54 -0500 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2016-04-14 21:00:54 -0500 |
commit | c73947814aab381a0761ecc919e6c5407c3fd617 (patch) | |
tree | 306249df450cea6c406d633ee38e19596d2cf102 | |
parent | f9b9f8a1a457f3a359c0d623fc5d0b261f458980 (diff) | |
download | toybox-c73947814aab381a0761ecc919e6c5407c3fd617.tar.gz |
Andy Chu pointed out an out of bounds access for zero length lines.
While we're at it, use unsigned for the line length.
-rw-r--r-- | toys/other/rev.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/toys/other/rev.c b/toys/other/rev.c index 4cf7214f..15066310 100644 --- a/toys/other/rev.c +++ b/toys/other/rev.c @@ -20,11 +20,11 @@ static void do_rev(int fd, char *name) char *c; for (;;) { - int len, i; + unsigned len, i; if (!(c = get_line(fd))) break; - len = strlen(c) - 1; - for (i = 0; i <= len/2; i++) { + len = strlen(c); + if (len--) for (i = 0; i <= len/2; i++) { char tmp = c[i]; c[i] = c[len-i]; |