Merge pull request #15628 from poettering/tmpfiles-fuzz-fix

systemd-tmpfiles fuzz issue fix
This commit is contained in:
Lennart Poettering 2020-04-29 09:41:46 +02:00 committed by GitHub
commit 384bd937fa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -256,10 +256,11 @@ static int log_unresolvable_specifier(const char *filename, unsigned line) {
* not considered as an error so log at LOG_NOTICE only for the first time
* and then downgrade this to LOG_DEBUG for the rest. */
log_full(notified ? LOG_DEBUG : LOG_NOTICE,
"[%s:%u] Failed to resolve specifier: %s, skipping",
filename, line,
arg_user ? "Required $XDG_... variable not defined" : "uninitialized /etc detected");
log_syntax(NULL,
notified ? LOG_DEBUG : LOG_NOTICE,
filename, line, 0,
"Failed to resolve specifier: %s, skipping",
arg_user ? "Required $XDG_... variable not defined" : "uninitialized /etc detected");
if (!notified)
log_notice("All rules containing unresolvable specifiers will be skipped.");
@ -2431,9 +2432,7 @@ static int specifier_expansion_from_arg(Item *i) {
case SET_XATTR:
case RECURSIVE_SET_XATTR:
assert(i->xattrs);
STRV_FOREACH (xattr, i->xattrs) {
STRV_FOREACH(xattr, i->xattrs) {
r = specifier_printf(*xattr, specifier_table, NULL, &resolved);
if (r < 0)
return r;
@ -2511,11 +2510,10 @@ static int parse_line(const char *fname, unsigned line, const char *buffer, bool
if (IN_SET(r, -EINVAL, -EBADSLT))
/* invalid quoting and such or an unknown specifier */
*invalid_config = true;
return log_error_errno(r, "[%s:%u] Failed to parse line: %m", fname, line);
return log_syntax(NULL, LOG_ERR, fname, line, r, "Failed to parse line: %m");
} else if (r < 2) {
*invalid_config = true;
log_error("[%s:%u] Syntax error.", fname, line);
return -EIO;
return log_syntax(NULL, LOG_ERR, fname, line, SYNTHETIC_ERRNO(EBADMSG), "Syntax error.");
}
if (!empty_or_dash(buffer)) {
@ -2526,8 +2524,7 @@ static int parse_line(const char *fname, unsigned line, const char *buffer, bool
if (isempty(action)) {
*invalid_config = true;
log_error("[%s:%u] Command too short '%s'.", fname, line, action);
return -EINVAL;
return log_syntax(NULL, LOG_ERR, fname, line, SYNTHETIC_ERRNO(EBADMSG), "Command too short '%s'.", action);
}
for (pos = 1; action[pos]; pos++) {
@ -2539,15 +2536,12 @@ static int parse_line(const char *fname, unsigned line, const char *buffer, bool
allow_failure = true;
else {
*invalid_config = true;
log_error("[%s:%u] Unknown modifiers in command '%s'",
fname, line, action);
return -EINVAL;
return log_syntax(NULL, LOG_ERR, fname, line, SYNTHETIC_ERRNO(EBADMSG), "Unknown modifiers in command '%s'", action);
}
}
if (boot && !arg_boot) {
log_debug("Ignoring entry %s \"%s\" because --boot is not specified.",
action, path);
log_syntax(NULL, LOG_DEBUG, fname, line, 0, "Ignoring entry %s \"%s\" because --boot is not specified.", action, path);
return 0;
}
@ -2561,7 +2555,7 @@ static int parse_line(const char *fname, unsigned line, const char *buffer, bool
if (r < 0) {
if (IN_SET(r, -EINVAL, -EBADSLT))
*invalid_config = true;
return log_error_errno(r, "[%s:%u] Failed to replace specifiers in '%s': %m", fname, line, path);
return log_syntax(NULL, LOG_ERR, fname, line, r, "Failed to replace specifiers in '%s': %m", path);
}
r = patch_var_run(fname, line, &i.path);
@ -2585,7 +2579,7 @@ static int parse_line(const char *fname, unsigned line, const char *buffer, bool
case RELABEL_PATH:
case RECURSIVE_RELABEL_PATH:
if (i.argument)
log_warning("[%s:%u] %c lines don't take argument fields, ignoring.", fname, line, i.type);
log_syntax(NULL, LOG_WARNING, fname, line, 0, "%c lines don't take argument fields, ignoring.", i.type);
break;
@ -2604,8 +2598,7 @@ static int parse_line(const char *fname, unsigned line, const char *buffer, bool
case WRITE_FILE:
if (!i.argument) {
*invalid_config = true;
log_error("[%s:%u] Write file requires argument.", fname, line);
return -EBADMSG;
return log_syntax(NULL, LOG_ERR, fname, line, SYNTHETIC_ERRNO(EBADMSG), "Write file requires argument.");
}
break;
@ -2617,8 +2610,7 @@ static int parse_line(const char *fname, unsigned line, const char *buffer, bool
} else if (!path_is_absolute(i.argument)) {
*invalid_config = true;
log_error("[%s:%u] Source path is not absolute.", fname, line);
return -EBADMSG;
return log_syntax(NULL, LOG_ERR, fname, line, SYNTHETIC_ERRNO(EBADMSG), "Source path '%s' is not absolute.", i.argument);
} else if (arg_root) {
char *p;
@ -2636,15 +2628,13 @@ static int parse_line(const char *fname, unsigned line, const char *buffer, bool
case CREATE_BLOCK_DEVICE:
if (!i.argument) {
*invalid_config = true;
log_error("[%s:%u] Device file requires argument.", fname, line);
return -EBADMSG;
return log_syntax(NULL, LOG_ERR, fname, line, SYNTHETIC_ERRNO(EBADMSG), "Device file requires argument.");
}
r = parse_dev(i.argument, &i.major_minor);
if (r < 0) {
*invalid_config = true;
log_error_errno(r, "[%s:%u] Can't parse device file major/minor '%s'.", fname, line, i.argument);
return -EBADMSG;
return log_syntax(NULL, LOG_ERR, fname, line, r, "Can't parse device file major/minor '%s'.", i.argument);
}
break;
@ -2653,8 +2643,8 @@ static int parse_line(const char *fname, unsigned line, const char *buffer, bool
case RECURSIVE_SET_XATTR:
if (!i.argument) {
*invalid_config = true;
log_error("[%s:%u] Set extended attribute requires argument.", fname, line);
return -EBADMSG;
return log_syntax(NULL, LOG_ERR, fname, line, SYNTHETIC_ERRNO(EBADMSG),
"Set extended attribute requires argument.");
}
r = parse_xattrs_from_arg(&i);
if (r < 0)
@ -2665,8 +2655,8 @@ static int parse_line(const char *fname, unsigned line, const char *buffer, bool
case RECURSIVE_SET_ACL:
if (!i.argument) {
*invalid_config = true;
log_error("[%s:%u] Set ACLs requires argument.", fname, line);
return -EBADMSG;
return log_syntax(NULL, LOG_ERR, fname, line, SYNTHETIC_ERRNO(EBADMSG),
"Set ACLs requires argument.");
}
r = parse_acls_from_arg(&i);
if (r < 0)
@ -2677,8 +2667,8 @@ static int parse_line(const char *fname, unsigned line, const char *buffer, bool
case RECURSIVE_SET_ATTRIBUTE:
if (!i.argument) {
*invalid_config = true;
log_error("[%s:%u] Set file attribute requires argument.", fname, line);
return -EBADMSG;
return log_syntax(NULL, LOG_ERR, fname, line, SYNTHETIC_ERRNO(EBADMSG),
"Set file attribute requires argument.");
}
r = parse_attribute_from_arg(&i);
if (IN_SET(r, -EINVAL, -EBADSLT))
@ -2688,15 +2678,15 @@ static int parse_line(const char *fname, unsigned line, const char *buffer, bool
break;
default:
log_error("[%s:%u] Unknown command type '%c'.", fname, line, (char) i.type);
*invalid_config = true;
return -EBADMSG;
return log_syntax(NULL, LOG_ERR, fname, line, SYNTHETIC_ERRNO(EBADMSG),
"Unknown command type '%c'.", (char) i.type);
}
if (!path_is_absolute(i.path)) {
log_error("[%s:%u] Path '%s' not absolute.", fname, line, i.path);
*invalid_config = true;
return -EBADMSG;
return log_syntax(NULL, LOG_ERR, fname, line, SYNTHETIC_ERRNO(EBADMSG),
"Path '%s' not absolute.", i.path);
}
path_simplify(i.path, false);
@ -2710,8 +2700,7 @@ static int parse_line(const char *fname, unsigned line, const char *buffer, bool
if (r < 0) {
if (IN_SET(r, -EINVAL, -EBADSLT))
*invalid_config = true;
return log_error_errno(r, "[%s:%u] Failed to substitute specifiers in argument: %m",
fname, line);
return log_syntax(NULL, LOG_ERR, fname, line, r, "Failed to substitute specifiers in argument: %m");
}
if (arg_root) {
@ -2729,7 +2718,7 @@ static int parse_line(const char *fname, unsigned line, const char *buffer, bool
r = get_user_creds(&u, &i.uid, NULL, NULL, NULL, USER_CREDS_ALLOW_MISSING);
if (r < 0) {
*invalid_config = true;
return log_error_errno(r, "[%s:%u] Unknown user '%s'.", fname, line, user);
return log_syntax(NULL, LOG_ERR, fname, line, r, "Failed to resolve user '%s': %m", user);
}
i.uid_set = true;
@ -2741,8 +2730,7 @@ static int parse_line(const char *fname, unsigned line, const char *buffer, bool
r = get_group_creds(&g, &i.gid, USER_CREDS_ALLOW_MISSING);
if (r < 0) {
*invalid_config = true;
log_error("[%s:%u] Unknown group '%s'.", fname, line, group);
return r;
return log_syntax(NULL, LOG_ERR, fname, line, r, "Failed to resolve group '%s'.", group);
}
i.gid_set = true;
@ -2757,10 +2745,10 @@ static int parse_line(const char *fname, unsigned line, const char *buffer, bool
mm++;
}
if (parse_mode(mm, &m) < 0) {
r = parse_mode(mm, &m);
if (r < 0) {
*invalid_config = true;
log_error("[%s:%u] Invalid mode '%s'.", fname, line, mode);
return -EBADMSG;
return log_syntax(NULL, LOG_ERR, fname, line, r, "Invalid mode '%s'.", mode);
}
i.mode = m;
@ -2776,10 +2764,10 @@ static int parse_line(const char *fname, unsigned line, const char *buffer, bool
a++;
}
if (parse_sec(a, &i.age) < 0) {
r = parse_sec(a, &i.age);
if (r < 0) {
*invalid_config = true;
log_error("[%s:%u] Invalid age '%s'.", fname, line, age);
return -EBADMSG;
return log_syntax(NULL, LOG_ERR, fname, line, r, "Invalid age '%s'.", age);
}
i.age_set = true;
@ -2793,8 +2781,7 @@ static int parse_line(const char *fname, unsigned line, const char *buffer, bool
for (n = 0; n < existing->n_items; n++) {
if (!item_compatible(existing->items + n, &i) && !i.append_or_force) {
log_notice("[%s:%u] Duplicate line for path \"%s\", ignoring.",
fname, line, i.path);
log_syntax(NULL, LOG_NOTICE, fname, line, 0, "Duplicate line for path \"%s\", ignoring.", i.path);
return 0;
}
}