diff options
author | Ray Lai <ray@cvs.openbsd.org> | 2006-10-24 03:29:55 +0000 |
---|---|---|
committer | Ray Lai <ray@cvs.openbsd.org> | 2006-10-24 03:29:55 +0000 |
commit | 722eec1d7eeea5cc78201fc7fc5dde4a2b5c7b23 (patch) | |
tree | 203a7823442188eefb007060e629be67f6d4b689 | |
parent | 77fbb0795041432193a525a3dc69e365c5960876 (diff) |
Check that string length != 0 before setting buf[strlen(buf) - 1].
OK cloder@.
-rw-r--r-- | usr.sbin/afs/src/lib/cmd/cmd.c | 3 | ||||
-rw-r--r-- | usr.sbin/afs/src/lib/sl/sl.c | 2 |
2 files changed, 3 insertions, 2 deletions
diff --git a/usr.sbin/afs/src/lib/cmd/cmd.c b/usr.sbin/afs/src/lib/cmd/cmd.c index b86e6e58cbe..ae353768192 100644 --- a/usr.sbin/afs/src/lib/cmd/cmd.c +++ b/usr.sbin/afs/src/lib/cmd/cmd.c @@ -801,7 +801,8 @@ cmd_ExtraText (const char *cmd, const char *sectionname, len = asprintf (§ion, "%%%s %s", class, name); while (fgets (buf, sizeof(buf), f) != NULL) { - buf[strlen(buf)-1] = '\0'; + if (buf[0] != '\0' && buf[strlen(buf) - 1] == '\n') + buf[strlen(buf) - 1] = '\0'; if (buf[0] == '#') continue; diff --git a/usr.sbin/afs/src/lib/sl/sl.c b/usr.sbin/afs/src/lib/sl/sl.c index dde33a6f123..33f8e1c8970 100644 --- a/usr.sbin/afs/src/lib/sl/sl.c +++ b/usr.sbin/afs/src/lib/sl/sl.c @@ -210,7 +210,7 @@ readline(char *prompt) fflush (stdout); if(fgets(buf, sizeof(buf), stdin) == NULL) return NULL; - if (buf[strlen(buf) - 1] == '\n') + if (buf[0] != '\0' && buf[strlen(buf) - 1] == '\n') buf[strlen(buf) - 1] = '\0'; return strdup(buf); } |