Merge pull request #12188 from poettering/coccinelle-fixlets

tree-wide: let's run coccinelle again
This commit is contained in:
Yu Watanabe 2019-04-03 01:46:54 +09:00 committed by GitHub
commit 33ca308f38
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 76 additions and 140 deletions

View file

@ -297,10 +297,8 @@ static int assess_root_directory(
assert(ret_description); assert(ret_description);
*ret_badness = *ret_badness =
(isempty(info->root_directory) || empty_or_root(info->root_directory) ||
path_equal(info->root_directory, "/")) && empty_or_root(info->root_image);
(isempty(info->root_image) ||
path_equal(info->root_image, "/"));
*ret_description = NULL; *ret_description = NULL;
return 0; return 0;

View file

@ -1411,9 +1411,9 @@ int open_parent(const char *path, int flags, mode_t mode) {
/* Let's insist on O_DIRECTORY since the parent of a file or directory is a directory. Except if we open an /* Let's insist on O_DIRECTORY since the parent of a file or directory is a directory. Except if we open an
* O_TMPFILE file, because in that case we are actually create a regular file below the parent directory. */ * O_TMPFILE file, because in that case we are actually create a regular file below the parent directory. */
if ((flags & O_PATH) == O_PATH) if (FLAGS_SET(flags, O_PATH))
flags |= O_DIRECTORY; flags |= O_DIRECTORY;
else if ((flags & O_TMPFILE) != O_TMPFILE) else if (!FLAGS_SET(flags, O_TMPFILE))
flags |= O_DIRECTORY|O_RDONLY; flags |= O_DIRECTORY|O_RDONLY;
fd = open(parent, flags, mode); fd = open(parent, flags, mode);

View file

@ -675,7 +675,7 @@ static int insert_into_order(uint16_t slot, bool first) {
} }
/* extend array */ /* extend array */
t = realloc(order, (n + 1) * sizeof(uint16_t)); t = reallocarray(order, n + 1, sizeof(uint16_t));
if (!t) if (!t)
return -ENOMEM; return -ENOMEM;
order = t; order = t;

View file

@ -269,10 +269,8 @@ static BOOLEAN line_edit(
case KEYPRESS(0, 0, CHAR_LINEFEED): case KEYPRESS(0, 0, CHAR_LINEFEED):
case KEYPRESS(0, 0, CHAR_CARRIAGE_RETURN): case KEYPRESS(0, 0, CHAR_CARRIAGE_RETURN):
if (StrCmp(line, line_in) != 0) { if (StrCmp(line, line_in) != 0)
*line_out = line; *line_out = TAKE_PTR(line);
line = NULL;
}
enter = TRUE; enter = TRUE;
exit = TRUE; exit = TRUE;
break; break;
@ -1258,8 +1256,7 @@ static VOID config_entry_bump_counters(
/* If the file we just renamed is the loader path, then let's update that. */ /* If the file we just renamed is the loader path, then let's update that. */
if (StrCmp(entry->loader, old_path) == 0) { if (StrCmp(entry->loader, old_path) == 0) {
FreePool(entry->loader); FreePool(entry->loader);
entry->loader = new_path; entry->loader = TAKE_PTR(new_path);
new_path = NULL;
} }
} }
@ -1360,10 +1357,8 @@ static VOID config_entry_add_from_file(
s = PoolPrint(L"%s %s", entry->options, new); s = PoolPrint(L"%s %s", entry->options, new);
FreePool(entry->options); FreePool(entry->options);
entry->options = s; entry->options = s;
} else { } else
entry->options = new; entry->options = TAKE_PTR(new);
new = NULL;
}
continue; continue;
} }
@ -1382,10 +1377,8 @@ static VOID config_entry_add_from_file(
s = PoolPrint(L"%s %s", initrd, entry->options); s = PoolPrint(L"%s %s", initrd, entry->options);
FreePool(entry->options); FreePool(entry->options);
entry->options = s; entry->options = s;
} else { } else
entry->options = initrd; entry->options = TAKE_PTR(initrd);
initrd = NULL;
}
} }
entry->device = device; entry->device = device;

View file

@ -122,8 +122,7 @@ EFI_STATUS efivar_get(const CHAR16 *name, CHAR16 **value) {
/* Return buffer directly if it happens to be NUL terminated already */ /* Return buffer directly if it happens to be NUL terminated already */
if (size >= 2 && buf[size-2] == 0 && buf[size-1] == 0) { if (size >= 2 && buf[size-2] == 0 && buf[size-1] == 0) {
*value = (CHAR16*) buf; *value = (CHAR16*) TAKE_PTR(buf);
buf = NULL;
return EFI_SUCCESS; return EFI_SUCCESS;
} }

View file

@ -922,10 +922,9 @@ static int run(int argc, char *argv[]) {
arg_count = (mask & CGROUP_MASK_PIDS) ? COUNT_PIDS : COUNT_USERSPACE_PROCESSES; arg_count = (mask & CGROUP_MASK_PIDS) ? COUNT_PIDS : COUNT_USERSPACE_PROCESSES;
if (arg_recursive_unset && arg_count == COUNT_PIDS) { if (arg_recursive_unset && arg_count == COUNT_PIDS)
log_error("Non-recursive counting is only supported when counting processes, not tasks. Use -P or -k."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Non-recursive counting is only supported when counting processes, not tasks. Use -P or -k.");
}
r = show_cgroup_get_path_and_warn(arg_machine, arg_root, &root); r = show_cgroup_get_path_and_warn(arg_machine, arg_root, &root);
if (r < 0) if (r < 0)

View file

@ -237,7 +237,7 @@ _public_ int sd_device_new_from_devnum(sd_device **ret, char type, dev_t devnum)
assert_return(IN_SET(type, 'b', 'c'), -EINVAL); assert_return(IN_SET(type, 'b', 'c'), -EINVAL);
/* use /sys/dev/{block,char}/<maj>:<min> link */ /* use /sys/dev/{block,char}/<maj>:<min> link */
snprintf(id, sizeof(id), "%u:%u", major(devnum), minor(devnum)); xsprintf(id, "%u:%u", major(devnum), minor(devnum));
syspath = strjoina("/sys/dev/", (type == 'b' ? "block" : "char"), "/", id); syspath = strjoina("/sys/dev/", (type == 'b' ? "block" : "char"), "/", id);

View file

@ -3116,7 +3116,7 @@ _public_ int sd_event_wait(sd_event *e, uint64_t timeout) {
timeout = 0; timeout = 0;
m = epoll_wait(e->epoll_fd, ev_queue, ev_queue_max, m = epoll_wait(e->epoll_fd, ev_queue, ev_queue_max,
timeout == (uint64_t) -1 ? -1 : (int) ((timeout + USEC_PER_MSEC - 1) / USEC_PER_MSEC)); timeout == (uint64_t) -1 ? -1 : (int) DIV_ROUND_UP(timeout, USEC_PER_MSEC));
if (m < 0) { if (m < 0) {
if (errno == EINTR) { if (errno == EINTR) {
e->state = SD_EVENT_PENDING; e->state = SD_EVENT_PENDING;

View file

@ -818,7 +818,7 @@ _public_ int sd_get_uids(uid_t **users) {
uid_t *t; uid_t *t;
n = MAX(16, 2*r); n = MAX(16, 2*r);
t = realloc(l, sizeof(uid_t) * n); t = reallocarray(l, sizeof(uid_t), n);
if (!t) if (!t)
return -ENOMEM; return -ENOMEM;

View file

@ -949,10 +949,8 @@ static int parse_argv(int argc, char *argv[]) {
case ARG_LINK_JOURNAL: case ARG_LINK_JOURNAL:
r = parse_link_journal(optarg, &arg_link_journal, &arg_link_journal_try); r = parse_link_journal(optarg, &arg_link_journal, &arg_link_journal_try);
if (r < 0) { if (r < 0)
log_error_errno(r, "Failed to parse link journal mode %s", optarg); return log_error_errno(r, "Failed to parse link journal mode %s", optarg);
return -EINVAL;
}
arg_settings_mask |= SETTING_LINK_JOURNAL; arg_settings_mask |= SETTING_LINK_JOURNAL;
break; break;
@ -1243,9 +1241,8 @@ static int parse_argv(int argc, char *argv[]) {
if (r < 0) if (r < 0)
return log_error_errno(r, "Failed to parse root hash: %s", optarg); return log_error_errno(r, "Failed to parse root hash: %s", optarg);
if (l < sizeof(sd_id128_t)) { if (l < sizeof(sd_id128_t)) {
log_error("Root hash must be at least 128bit long: %s", optarg);
free(k); free(k);
return -EINVAL; return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Root hash must be at least 128bit long: %s", optarg);
} }
free(arg_root_hash); free(arg_root_hash);
@ -1389,10 +1386,8 @@ static int parse_argv(int argc, char *argv[]) {
"read-only\n" "read-only\n"
"passive\n" "passive\n"
"pipe"); "pipe");
else { else
log_error("Unknown console mode: %s", optarg); return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Unknown console mode: %s", optarg);
return -EINVAL;
}
arg_settings_mask |= SETTING_CONSOLE_MODE; arg_settings_mask |= SETTING_CONSOLE_MODE;
break; break;
@ -2618,10 +2613,8 @@ static int determine_names(void) {
return log_error_errno(r, "Failed to determine current directory: %m"); return log_error_errno(r, "Failed to determine current directory: %m");
} }
if (!arg_directory && !arg_image) { if (!arg_directory && !arg_image)
log_error("Failed to determine path, please use -D or -i."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Failed to determine path, please use -D or -i.");
return -EINVAL;
}
} }
if (!arg_machine) { if (!arg_machine) {
@ -2644,10 +2637,8 @@ static int determine_names(void) {
return log_oom(); return log_oom();
hostname_cleanup(arg_machine); hostname_cleanup(arg_machine);
if (!machine_name_is_valid(arg_machine)) { if (!machine_name_is_valid(arg_machine))
log_error("Failed to determine machine name automatically, please use -M."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Failed to determine machine name automatically, please use -M.");
return -EINVAL;
}
if (arg_ephemeral) { if (arg_ephemeral) {
char *b; char *b;
@ -2774,10 +2765,8 @@ static int patch_sysctl(void) {
break; break;
} }
if (!good) { if (!good)
log_error("Refusing to write to sysctl '%s', as it is not safe in the selected namespaces.", *k); return log_error_errno(SYNTHETIC_ERRNO(EPERM), "Refusing to write to sysctl '%s', as it is not safe in the selected namespaces.", *k);
return -EPERM;
}
r = sysctl_write(*k, *v); r = sysctl_write(*k, *v);
if (r < 0) if (r < 0)
@ -4162,10 +4151,9 @@ static int run_container(int master,
log_debug_errno(r, "Cannot determine if passed network namespace path '%s' really refers to a network namespace, assuming it does.", arg_network_namespace_path); log_debug_errno(r, "Cannot determine if passed network namespace path '%s' really refers to a network namespace, assuming it does.", arg_network_namespace_path);
else if (r < 0) else if (r < 0)
return log_error_errno(r, "Failed to check %s fs type: %m", arg_network_namespace_path); return log_error_errno(r, "Failed to check %s fs type: %m", arg_network_namespace_path);
else if (r == 0) { else if (r == 0)
log_error("Path %s doesn't refer to a network namespace, refusing.", arg_network_namespace_path); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Path %s doesn't refer to a network namespace, refusing.", arg_network_namespace_path);
}
} }
*pid = raw_clone(SIGCHLD|CLONE_NEWNS); *pid = raw_clone(SIGCHLD|CLONE_NEWNS);
@ -4228,10 +4216,8 @@ static int run_container(int master,
l = recv(uid_shift_socket_pair[0], &arg_uid_shift, sizeof arg_uid_shift, 0); l = recv(uid_shift_socket_pair[0], &arg_uid_shift, sizeof arg_uid_shift, 0);
if (l < 0) if (l < 0)
return log_error_errno(errno, "Failed to read UID shift: %m"); return log_error_errno(errno, "Failed to read UID shift: %m");
if (l != sizeof arg_uid_shift) { if (l != sizeof arg_uid_shift)
log_error("Short read while reading UID shift."); return log_error_errno(SYNTHETIC_ERRNO(EIO), "Short read while reading UID shift.");
return -EIO;
}
if (arg_userns_mode == USER_NAMESPACE_PICK) { if (arg_userns_mode == USER_NAMESPACE_PICK) {
/* If we are supposed to pick the UID shift, let's try to use the shift read from the /* If we are supposed to pick the UID shift, let's try to use the shift read from the
@ -4245,10 +4231,8 @@ static int run_container(int master,
l = send(uid_shift_socket_pair[0], &arg_uid_shift, sizeof arg_uid_shift, MSG_NOSIGNAL); l = send(uid_shift_socket_pair[0], &arg_uid_shift, sizeof arg_uid_shift, MSG_NOSIGNAL);
if (l < 0) if (l < 0)
return log_error_errno(errno, "Failed to send UID shift: %m"); return log_error_errno(errno, "Failed to send UID shift: %m");
if (l != sizeof arg_uid_shift) { if (l != sizeof arg_uid_shift)
log_error("Short write while writing UID shift."); return log_error_errno(SYNTHETIC_ERRNO(EIO), "Short write while writing UID shift.");
return -EIO;
}
} }
} }
@ -4257,11 +4241,9 @@ static int run_container(int master,
l = recv(unified_cgroup_hierarchy_socket_pair[0], &arg_unified_cgroup_hierarchy, sizeof(arg_unified_cgroup_hierarchy), 0); l = recv(unified_cgroup_hierarchy_socket_pair[0], &arg_unified_cgroup_hierarchy, sizeof(arg_unified_cgroup_hierarchy), 0);
if (l < 0) if (l < 0)
return log_error_errno(errno, "Failed to read cgroup mode: %m"); return log_error_errno(errno, "Failed to read cgroup mode: %m");
if (l != sizeof(arg_unified_cgroup_hierarchy)) { if (l != sizeof(arg_unified_cgroup_hierarchy))
log_error("Short read while reading cgroup mode (%zu bytes).%s", return log_error_errno(SYNTHETIC_ERRNO(EIO), "Short read while reading cgroup mode (%zu bytes).%s",
l, l == 0 ? " The child is most likely dead." : ""); l, l == 0 ? " The child is most likely dead." : "");
return -EIO;
}
} }
/* Wait for the outer child. */ /* Wait for the outer child. */
@ -4275,19 +4257,15 @@ static int run_container(int master,
l = recv(pid_socket_pair[0], pid, sizeof *pid, 0); l = recv(pid_socket_pair[0], pid, sizeof *pid, 0);
if (l < 0) if (l < 0)
return log_error_errno(errno, "Failed to read inner child PID: %m"); return log_error_errno(errno, "Failed to read inner child PID: %m");
if (l != sizeof *pid) { if (l != sizeof *pid)
log_error("Short read while reading inner child PID."); return log_error_errno(SYNTHETIC_ERRNO(EIO), "Short read while reading inner child PID.");
return -EIO;
}
/* We also retrieve container UUID in case it was generated by outer child */ /* We also retrieve container UUID in case it was generated by outer child */
l = recv(uuid_socket_pair[0], &arg_uuid, sizeof arg_uuid, 0); l = recv(uuid_socket_pair[0], &arg_uuid, sizeof arg_uuid, 0);
if (l < 0) if (l < 0)
return log_error_errno(errno, "Failed to read container machine ID: %m"); return log_error_errno(errno, "Failed to read container machine ID: %m");
if (l != sizeof(arg_uuid)) { if (l != sizeof(arg_uuid))
log_error("Short read while reading container machined ID."); return log_error_errno(SYNTHETIC_ERRNO(EIO), "Short read while reading container machined ID.");
return -EIO;
}
/* We also retrieve the socket used for notifications generated by outer child */ /* We also retrieve the socket used for notifications generated by outer child */
notify_socket = receive_one_fd(notify_socket_pair[0], 0); notify_socket = receive_one_fd(notify_socket_pair[0], 0);
@ -4298,10 +4276,8 @@ static int run_container(int master,
log_debug("Init process invoked as PID "PID_FMT, *pid); log_debug("Init process invoked as PID "PID_FMT, *pid);
if (arg_userns_mode != USER_NAMESPACE_NO) { if (arg_userns_mode != USER_NAMESPACE_NO) {
if (!barrier_place_and_sync(&barrier)) { /* #1 */ if (!barrier_place_and_sync(&barrier)) /* #1 */
log_error("Child died too early."); return log_error_errno(SYNTHETIC_ERRNO(ESRCH), "Child died too early.");
return -ESRCH;
}
r = setup_uid_map(*pid); r = setup_uid_map(*pid);
if (r < 0) if (r < 0)
@ -4313,10 +4289,8 @@ static int run_container(int master,
if (arg_private_network) { if (arg_private_network) {
if (!arg_network_namespace_path) { if (!arg_network_namespace_path) {
/* Wait until the child has unshared its network namespace. */ /* Wait until the child has unshared its network namespace. */
if (!barrier_place_and_sync(&barrier)) { /* #3 */ if (!barrier_place_and_sync(&barrier)) /* #3 */
log_error("Child died too early"); return log_error_errno(SYNTHETIC_ERRNO(ESRCH), "Child died too early");
return -ESRCH;
}
} }
r = move_network_interfaces(*pid, arg_network_interfaces); r = move_network_interfaces(*pid, arg_network_interfaces);
@ -4472,10 +4446,8 @@ static int run_container(int master,
return r; return r;
/* Let the child know that we are ready and wait that the child is completely ready now. */ /* Let the child know that we are ready and wait that the child is completely ready now. */
if (!barrier_place_and_sync(&barrier)) { /* #5 */ if (!barrier_place_and_sync(&barrier)) /* #5 */
log_error("Child died too early."); return log_error_errno(SYNTHETIC_ERRNO(ESRCH), "Child died too early.");
return -ESRCH;
}
/* At this point we have made use of the UID we picked, and thus nss-mymachines /* At this point we have made use of the UID we picked, and thus nss-mymachines
* will make them appear in getpwuid(), thus we can release the /etc/passwd lock. */ * will make them appear in getpwuid(), thus we can release the /etc/passwd lock. */

View file

@ -119,10 +119,8 @@ int ifname_mangle(const char *s) {
} }
} }
if (arg_ifindex > 0 && arg_ifindex != ifi) { if (arg_ifindex > 0 && arg_ifindex != ifi)
log_error("Specified multiple different interfaces. Refusing."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Specified multiple different interfaces. Refusing.");
return -EINVAL;
}
arg_ifindex = ifi; arg_ifindex = ifi;
free_and_replace(arg_ifname, iface); free_and_replace(arg_ifname, iface);

View file

@ -756,7 +756,7 @@ static int bus_print_property(const char *name, const char *expected_value, sd_b
if ((u & NAMESPACE_FLAGS_ALL) == 0) if ((u & NAMESPACE_FLAGS_ALL) == 0)
result = "yes"; result = "yes";
else if ((u & NAMESPACE_FLAGS_ALL) == NAMESPACE_FLAGS_ALL) else if (FLAGS_SET(u, NAMESPACE_FLAGS_ALL))
result = "no"; result = "no";
else { else {
r = namespace_flags_to_string(u, &s); r = namespace_flags_to_string(u, &s);

View file

@ -3297,10 +3297,8 @@ int json_dispatch_boolean(const char *name, JsonVariant *variant, JsonDispatchFl
assert(variant); assert(variant);
assert(b); assert(b);
if (!json_variant_is_boolean(variant)) { if (!json_variant_is_boolean(variant))
json_log(variant, flags, 0, "JSON field '%s' is not a boolean.", strna(name)); return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not a boolean.", strna(name));
return -EINVAL;
}
*b = json_variant_boolean(variant); *b = json_variant_boolean(variant);
return 0; return 0;
@ -3312,10 +3310,8 @@ int json_dispatch_tristate(const char *name, JsonVariant *variant, JsonDispatchF
assert(variant); assert(variant);
assert(b); assert(b);
if (!json_variant_is_boolean(variant)) { if (!json_variant_is_boolean(variant))
json_log(variant, flags, 0, "JSON field '%s' is not a boolean.", strna(name)); return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not a boolean.", strna(name));
return -EINVAL;
}
*b = json_variant_boolean(variant); *b = json_variant_boolean(variant);
return 0; return 0;
@ -3327,10 +3323,8 @@ int json_dispatch_integer(const char *name, JsonVariant *variant, JsonDispatchFl
assert(variant); assert(variant);
assert(i); assert(i);
if (!json_variant_is_integer(variant)) { if (!json_variant_is_integer(variant))
json_log(variant, flags, 0, "JSON field '%s' is not an integer.", strna(name)); return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not an integer.", strna(name));
return -EINVAL;
}
*i = json_variant_integer(variant); *i = json_variant_integer(variant);
return 0; return 0;
@ -3342,10 +3336,8 @@ int json_dispatch_unsigned(const char *name, JsonVariant *variant, JsonDispatchF
assert(variant); assert(variant);
assert(u); assert(u);
if (!json_variant_is_unsigned(variant)) { if (!json_variant_is_unsigned(variant))
json_log(variant, flags, 0, "JSON field '%s' is not an unsigned integer.", strna(name)); return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not an unsigned integer.", strna(name));
return -EINVAL;
}
*u = json_variant_unsigned(variant); *u = json_variant_unsigned(variant);
return 0; return 0;
@ -3357,15 +3349,11 @@ int json_dispatch_uint32(const char *name, JsonVariant *variant, JsonDispatchFla
assert(variant); assert(variant);
assert(u); assert(u);
if (!json_variant_is_unsigned(variant)) { if (!json_variant_is_unsigned(variant))
json_log(variant, flags, 0, "JSON field '%s' is not an unsigned integer.", strna(name)); return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not an unsigned integer.", strna(name));
return -EINVAL;
}
if (json_variant_unsigned(variant) > UINT32_MAX) { if (json_variant_unsigned(variant) > UINT32_MAX)
json_log(variant, flags, 0, "JSON field '%s' out of bounds.", strna(name)); return json_log(variant, flags, SYNTHETIC_ERRNO(ERANGE), "JSON field '%s' out of bounds.", strna(name));
return -ERANGE;
}
*u = (uint32_t) json_variant_unsigned(variant); *u = (uint32_t) json_variant_unsigned(variant);
return 0; return 0;
@ -3377,15 +3365,11 @@ int json_dispatch_int32(const char *name, JsonVariant *variant, JsonDispatchFlag
assert(variant); assert(variant);
assert(i); assert(i);
if (!json_variant_is_integer(variant)) { if (!json_variant_is_integer(variant))
json_log(variant, flags, 0, "JSON field '%s' is not an integer.", strna(name)); return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not an integer.", strna(name));
return -EINVAL;
}
if (json_variant_integer(variant) < INT32_MIN || json_variant_integer(variant) > INT32_MAX) { if (json_variant_integer(variant) < INT32_MIN || json_variant_integer(variant) > INT32_MAX)
json_log(variant, flags, 0, "JSON field '%s' out of bounds.", strna(name)); return json_log(variant, flags, SYNTHETIC_ERRNO(ERANGE), "JSON field '%s' out of bounds.", strna(name));
return -ERANGE;
}
*i = (int32_t) json_variant_integer(variant); *i = (int32_t) json_variant_integer(variant);
return 0; return 0;
@ -3403,10 +3387,8 @@ int json_dispatch_string(const char *name, JsonVariant *variant, JsonDispatchFla
return 0; return 0;
} }
if (!json_variant_is_string(variant)) { if (!json_variant_is_string(variant))
json_log(variant, flags, 0, "JSON field '%s' is not a string.", strna(name)); return json_log(variant, flags, SYNTHETIC_ERRNO(EINVAL), "JSON field '%s' is not a string.", strna(name));
return -EINVAL;
}
r = free_and_strdup(s, json_variant_string(variant)); r = free_and_strdup(s, json_variant_string(variant));
if (r < 0) if (r < 0)
@ -3429,20 +3411,16 @@ int json_dispatch_strv(const char *name, JsonVariant *variant, JsonDispatchFlags
return 0; return 0;
} }
if (!json_variant_is_array(variant)) { if (!json_variant_is_array(variant))
json_log(variant, 0, flags, "JSON field '%s' is not an array.", strna(name)); return json_log(variant, SYNTHETIC_ERRNO(EINVAL), flags, "JSON field '%s' is not an array.", strna(name));
return -EINVAL;
}
for (i = 0; i < json_variant_elements(variant); i++) { for (i = 0; i < json_variant_elements(variant); i++) {
JsonVariant *e; JsonVariant *e;
assert_se(e = json_variant_by_index(variant, i)); assert_se(e = json_variant_by_index(variant, i));
if (!json_variant_is_string(e)) { if (!json_variant_is_string(e))
json_log(e, 0, flags, "JSON array element is not a string."); return json_log(e, flags, SYNTHETIC_ERRNO(EINVAL), "JSON array element is not a string.");
return -EINVAL;
}
r = strv_extend(&l, json_variant_string(e)); r = strv_extend(&l, json_variant_string(e));
if (r < 0) if (r < 0)

View file

@ -1645,8 +1645,7 @@ static bool match_key(UdevRules *rules, struct token *token, const char *val) {
char *pos; char *pos;
bool match = false; bool match = false;
if (!val) val = strempty(val);
val = "";
switch (token->key.glob) { switch (token->key.glob) {
case GL_PLAIN: case GL_PLAIN: