]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
hexdecoct: implicitly parse URL-safe base64 format, too
authorLennart Poettering <lennart@poettering.net>
Fri, 3 Nov 2023 13:07:39 +0000 (14:07 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 3 Nov 2023 20:35:24 +0000 (21:35 +0100)
JSON-I (RFC 7493) suggests to use the URL safe base64 alphabet, rather
than the regular one when encoding binary data in JSON strings. We
generally uses the regular alphabet though.

Let's be tolerant in what we parse however: simply accept both formats
when we parse base64.

This does nothing about base64 generation though, only about parsing.

src/basic/hexdecoct.c

index 898ed83f862ac6dd759febcd4cefb446bbf39918..ea683eb42734eb1fc6f1252d42c8451567e5e2dc 100644 (file)
@@ -553,12 +553,12 @@ int unbase64char(char c) {
 
         offset += '9' - '0' + 1;
 
-        if (c == '+')
+        if (IN_SET(c, '+', '-')) /* Support both the regular and the URL safe character set (see above) */
                 return offset;
 
         offset++;
 
-        if (c == '/')
+        if (IN_SET(c, '/', '_')) /* ditto */
                 return offset;
 
         return -EINVAL;