From: Roy Marples Date: Fri, 23 Dec 2022 17:35:29 +0000 (+0000) Subject: options: Fix parsing of strings. X-Git-Tag: v10.0.0~19 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6797c08b662e9a1ffb475f2b189603e88fc2f3cc;p=thirdparty%2Fdhcpcd.git options: Fix parsing of strings. If we are not passed a buffer we should blindly return the result of trying to parse it has as a hex string - it will be zero. Fixes 133. --- diff --git a/src/if-options.c b/src/if-options.c index 6d11a6f7..20ebf17f 100644 --- a/src/if-options.c +++ b/src/if-options.c @@ -266,9 +266,13 @@ parse_str(char *sbuf, size_t slen, const char *str, int flags) } } else { l = (size_t)hwaddr_aton(NULL, str); - if (sbuf == NULL) - return (ssize_t)l; - if ((ssize_t) l != -1 && l > 1) { + if (l > 0) { + if ((ssize_t)l == -1) { + errno = ENOBUFS; + return -1; + } + if (sbuf == NULL) + return (ssize_t)l; if (l > slen) { errno = ENOBUFS; return -1; @@ -2096,7 +2100,7 @@ err_sla: arg = fp; fp = strend(arg); if (fp == NULL) { - logerrx("authtoken requies an a key"); + logerrx("authtoken requires a realm"); goto invalid_token; } *fp++ = '\0'; @@ -2149,7 +2153,7 @@ err_sla: if (s == -1) logerr("token_len"); else - logerrx("authtoken needs a key"); + logerrx("authtoken requires a key"); goto invalid_token; } token->key_len = (size_t)s;