]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
options: Fix parsing of strings.
authorRoy Marples <roy@marples.name>
Fri, 23 Dec 2022 17:35:29 +0000 (17:35 +0000)
committerRoy Marples <roy@marples.name>
Fri, 23 Dec 2022 17:35:29 +0000 (17:35 +0000)
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.

src/if-options.c

index 6d11a6f759a9edaa9076191baf821fc12fcfbd47..20ebf17fa521bf68f94aef02a06fb4133fc765b4 100644 (file)
@@ -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;