conf-parser: introduce CONFIG_PARSE_STRING_ASCII flag

When the flag is set, the string which contains non-ascii characters
will be refused.
This commit is contained in:
Yu Watanabe
2022-03-10 14:43:48 +09:00
parent 3f87eaa5d8
commit e289ce7f67
2 changed files with 12 additions and 0 deletions
+9
View 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));
}
+3
View 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) \