telnet: Fix telnet segfault when invalid set or help help commands

Silently ignore invalid set ' ' and invalid help help commands.
This is the same fix applied by NetBSD in hg commit 1019940:4f248823eaff.

PR:		265097
Reported by:	Simon Josefsson <simon@josefsson.org>
Obtained from:	NetBSD hg commit 1019940:4f248823eaff
		NetBSD PR/56918
MFC after:	1 week
This commit is contained in:
Cy Schubert 2022-07-13 21:42:06 -07:00
parent ac19e54390
commit a7399ea2dd

View file

@ -939,7 +939,7 @@ setcmd(int argc, char *argv[])
}
ct = getset(argv[1]);
if (ct == 0) {
if (ct == 0 || !(ct->name && ct->name[0] != ' ')) {
c = GETTOGGLE(argv[1]);
if (c == 0) {
fprintf(stderr, "'%s': unknown argument ('set ?' for help).\n",
@ -1015,7 +1015,7 @@ unsetcmd(int argc, char *argv[])
while (argc--) {
name = *argv++;
ct = getset(name);
if (ct == 0) {
if (ct == 0 || !(ct->name && ct->name[0] != ' ')) {
c = GETTOGGLE(name);
if (c == 0) {
fprintf(stderr, "'%s': unknown argument ('unset ?' for help).\n",
@ -2702,7 +2702,7 @@ help(int argc, char *argv[])
printf("?Ambiguous help command %s\n", arg);
else if (c == (Command *)0)
printf("?Invalid help command %s\n", arg);
else
else if (c->help)
printf("%s\n", c->help);
}
return 0;