]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
conf-parser: introduce CONFIG_PARSE_STRING_ASCII flag
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 7 Mar 2022 07:09:23 +0000 (16:09 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 10 Mar 2022 05:43:48 +0000 (14:43 +0900)
When the flag is set, the string which contains non-ascii characters
will be refused.

src/shared/conf-parser.c
src/shared/conf-parser.h

index 1640500d57c2081a81af37acfe3a343995fe9b80..ceadfdb7233705e58f1e3e37d15b30d7cbd6521b 100644 (file)
@@ -894,6 +894,15 @@ int config_parse_string(
                 return 0;
         }
 
+        if (FLAGS_SET(ltype, CONFIG_PARSE_STRING_ASCII) && !ascii_is_valid(rvalue)) {
+                _cleanup_free_ char *escaped = NULL;
+
+                escaped = cescape(rvalue);
+                log_syntax(unit, LOG_WARNING, filename, line, 0,
+                           "Specified string contains invalid ASCII characters, ignoring: %s", strna(escaped));
+                return 0;
+        }
+
         return free_and_strdup_warn(s, empty_to_null(rvalue));
 }
 
index b0d6cebc97287dd1863aa719ecc727cee5afc2a7..f3044b0ca6c0f725907d0c0c8484aa1bee2092bf 100644 (file)
@@ -204,6 +204,9 @@ typedef enum Disabled {
 
 typedef enum ConfigParseStringFlags {
         CONFIG_PARSE_STRING_SAFE  = 1 << 0,
+        CONFIG_PARSE_STRING_ASCII = 1 << 1,
+
+        CONFIG_PARSE_STRING_SAFE_AND_ASCII = CONFIG_PARSE_STRING_SAFE | CONFIG_PARSE_STRING_ASCII,
 } ConfigParseStringFlags;
 
 #define DEFINE_CONFIG_PARSE(function, parser, msg)                      \