aboutsummaryrefslogtreecommitdiff
path: root/toys/other/rev.c
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2016-04-14 21:00:54 -0500
committerRob Landley <rob@landley.net>2016-04-14 21:00:54 -0500
commitc73947814aab381a0761ecc919e6c5407c3fd617 (patch)
tree306249df450cea6c406d633ee38e19596d2cf102 /toys/other/rev.c
parentf9b9f8a1a457f3a359c0d623fc5d0b261f458980 (diff)
downloadtoybox-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.
Diffstat (limited to 'toys/other/rev.c')
-rw-r--r--toys/other/rev.c6
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];