diff options
author | Ray Lai <ray@cvs.openbsd.org> | 2006-11-01 06:02:30 +0000 |
---|---|---|
committer | Ray Lai <ray@cvs.openbsd.org> | 2006-11-01 06:02:30 +0000 |
commit | 496a33d9d6462c95ad3282dd4ffdec564c198d1a (patch) | |
tree | c2e18a3b524b751db49f5a42d3b494d3e3166b68 /usr.bin | |
parent | a717488db5cb5e337f2ff1357e6b6e04617217a1 (diff) |
Don't overwrite line[strlen(line) - 1] when line is zero-length.
Initial patch by Charles Longeau <chl at tuxfamily dot org>.
OK kjell@.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/mg/dired.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/usr.bin/mg/dired.c b/usr.bin/mg/dired.c index 2243b7f71ce..ba44d6c0e8d 100644 --- a/usr.bin/mg/dired.c +++ b/usr.bin/mg/dired.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dired.c,v 1.41 2006/07/25 08:27:09 kjell Exp $ */ +/* $OpenBSD: dired.c,v 1.42 2006/11/01 06:02:29 ray Exp $ */ /* This file is in the public domain. */ @@ -622,7 +622,10 @@ dired_(char *dname) } line[0] = line[1] = ' '; while (fgets(&line[2], sizeof(line) - 2, dirpipe) != NULL) { - line[strlen(line) - 1] = '\0'; /* remove ^J */ + char *p; + + if ((p = strchr(line, '\n')) != NULL) + *p = '\0'; /* remove ^J */ (void) addline(bp, line); } if (pclose(dirpipe) == -1) { |