=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/telnet/commands.c,v retrieving revision 1.85 retrieving revision 1.86 diff -c -r1.85 -r1.86 *** src/usr.bin/telnet/commands.c 2017/07/19 12:25:52 1.85 --- src/usr.bin/telnet/commands.c 2018/09/30 14:35:32 1.86 *************** *** 1,4 **** ! /* $OpenBSD: commands.c,v 1.85 2017/07/19 12:25:52 deraadt Exp $ */ /* $NetBSD: commands.c,v 1.14 1996/03/24 22:03:48 jtk Exp $ */ /* --- 1,4 ---- ! /* $OpenBSD: commands.c,v 1.86 2018/09/30 14:35:32 deraadt Exp $ */ /* $NetBSD: commands.c,v 1.14 1996/03/24 22:03:48 jtk Exp $ */ /* *************** *** 58,76 **** int needconnect; /* Do we need to be connected to execute? */ } Command; static char line[256]; static int margc; ! static char *margv[20]; ! static void makeargv(void) { char *cp, *cp2, c; char **argp = margv; margc = 0; cp = line; while ((c = *cp)) { int inquote = 0; while (isspace((unsigned char)c)) c = *++cp; --- 58,84 ---- int needconnect; /* Do we need to be connected to execute? */ } Command; + #define MAXARGV 20 + static char line[256]; static int margc; ! static char *margv[MAXARGV+1]; ! static int makeargv(void) { char *cp, *cp2, c; char **argp = margv; + int ret = 0; margc = 0; cp = line; while ((c = *cp)) { + if (margc >= MAXARGV) { + printf("too many arguments\n"); + ret = 1; + break; + } int inquote = 0; while (isspace((unsigned char)c)) c = *++cp; *************** *** 105,110 **** --- 113,119 ---- cp++; } *argp++ = 0; + return (ret); } /* *************** *** 1703,1709 **** continue; gotmachine = 1; } ! makeargv(); if (margv[0] == 0) continue; c = getcmd(margv[0]); --- 1712,1719 ---- continue; gotmachine = 1; } ! if (makeargv()) ! continue; if (margv[0] == 0) continue; c = getcmd(margv[0]); *************** *** 1747,1753 **** strlcpy(line, "open ", sizeof(line)); printf("(to) "); (void) fgets(&line[strlen(line)], sizeof(line) - strlen(line), stdin); ! makeargv(); argc = margc; argv = margv; } --- 1757,1764 ---- strlcpy(line, "open ", sizeof(line)); printf("(to) "); (void) fgets(&line[strlen(line)], sizeof(line) - strlen(line), stdin); ! if (makeargv()) ! return 0; argc = margc; argv = margv; } *************** *** 2017,2023 **** } if (line[0] == 0) break; ! makeargv(); if (margv[0] == 0) { break; } --- 2028,2035 ---- } if (line[0] == 0) break; ! if (makeargv()) ! break; if (margv[0] == 0) { break; }