From 259ea3b8eab1f91025fa162e30a8b625ec85ff2c Mon Sep 17 00:00:00 2001 From: op Date: Mon, 26 Aug 2024 21:34:32 +0000 Subject: [PATCH] replace hand-rolled number parser with strtonum original report by Collin Funk ok bluhm, millert --- usr.bin/telnet/commands.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/usr.bin/telnet/commands.c b/usr.bin/telnet/commands.c index dcf3a77a973..4e9b4def592 100644 --- a/usr.bin/telnet/commands.c +++ b/usr.bin/telnet/commands.c @@ -1,4 +1,4 @@ -/* $OpenBSD: commands.c,v 1.88 2022/12/26 19:16:03 jmc Exp $ */ +/* $OpenBSD: commands.c,v 1.89 2024/08/26 21:34:32 op Exp $ */ /* $NetBSD: commands.c,v 1.14 1996/03/24 22:03:48 jtk Exp $ */ /* @@ -358,6 +358,7 @@ send_tncmd(void (*func)(int, int), char *cmd, char *name) { char **cpp; extern char *telopts[]; + const char *errstr; int val = 0; if (isprefix(name, "help") || isprefix(name, "?")) { @@ -389,20 +390,10 @@ send_tncmd(void (*func)(int, int), char *cmd, char *name) if (cpp) { val = cpp - telopts; } else { - char *cp = name; - - while (*cp >= '0' && *cp <= '9') { - val *= 10; - val += *cp - '0'; - cp++; - } - if (*cp != 0) { - fprintf(stderr, "'%s': unknown argument ('send %s ?' for help).\r\n", - name, cmd); - return 0; - } else if (val < 0 || val > 255) { - fprintf(stderr, "'%s': bad value ('send %s ?' for help).\r\n", - name, cmd); + val = strtonum(name, 0, 255, &errstr); + if (errstr) { + fprintf(stderr, "'%s': %s ('send %s ?' for help).\r\n", + name, errstr, cmd); return 0; } } -- 2.20.1