diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2004-09-30 18:20:07 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2004-09-30 18:20:07 +0000 |
commit | 8fc4a2fd80c7e5bec4e8bf2e5abc7eec77f59038 (patch) | |
tree | 3649cacb6c9ee1fe532ef3d9ec9c148cbf314a8f /usr.sbin | |
parent | be18bcfb9e3051565c287722b6e6ad2b7d071cbc (diff) |
Avoid a segfault if only whitespace characters are entered at the
lpc> prompt and fix an off by one when splitting a line into an
argument vector. Based on a patch from Patrick Latifi. OK otto@
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/lpr/lpc/lpc.c | 33 |
1 files changed, 12 insertions, 21 deletions
diff --git a/usr.sbin/lpr/lpc/lpc.c b/usr.sbin/lpr/lpc/lpc.c index 05449349f68..ac389b731ee 100644 --- a/usr.sbin/lpr/lpc/lpc.c +++ b/usr.sbin/lpr/lpc/lpc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lpc.c,v 1.16 2003/06/02 23:36:53 millert Exp $ */ +/* $OpenBSD: lpc.c,v 1.17 2004/09/30 18:20:06 millert Exp $ */ /* $NetBSD: lpc.c,v 1.11 2001/11/14 03:01:15 enami Exp $ */ /* @@ -41,7 +41,7 @@ static const char copyright[] = #if 0 static const char sccsid[] = "@(#)lpc.c 8.3 (Berkeley) 4/28/95"; #else -static const char rcsid[] = "$OpenBSD: lpc.c,v 1.16 2003/06/02 23:36:53 millert Exp $"; +static const char rcsid[] = "$OpenBSD: lpc.c,v 1.17 2004/09/30 18:20:06 millert Exp $"; #endif #endif /* not lint */ @@ -159,9 +159,9 @@ cmdscanner(void) } siginterrupt(SIGINT, 0); - if (cmdline[0] == 0 || cmdline[0] == '\n') - break; makeargv(); + if (margc == 0) + break; c = getcmd(margv[0]); if (c == (struct cmd *)-1) { printf("?Ambiguous command\n"); @@ -213,26 +213,17 @@ getcmd(char *name) static void makeargv(void) { - char *cp; - char **argp = margv; - int n = 0; + char *cp = cmdline; + char **ap = margv; margc = 0; - for (cp = cmdline; *cp && (cp - cmdline) < sizeof(cmdline) && - n < MAX_MARGV; n++) { - while (isspace(*cp)) - cp++; - if (*cp == '\0') - break; - *argp++ = cp; - margc += 1; - while (*cp != '\0' && !isspace(*cp)) - cp++; - if (*cp == '\0') - break; - *cp++ = '\0'; + while (margc < MAX_MARGV - 1 && (*ap = strsep(&cp, " \t\n")) != NULL) { + if (**ap != '\0') { + ap++; + margc++; + } } - *argp++ = 0; + *ap = NULL; } #define HELPINDENT ((int)sizeof("directory")) |