mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-03-08 20:58:20 +03:00
Merge pull request #10381 from poettering/coverity-fixes
fixes for various recent coverity issues
This commit is contained in:
commit
18094bdcf4
@ -73,11 +73,11 @@ typedef struct TableData {
|
||||
} TableData;
|
||||
|
||||
static size_t TABLE_CELL_TO_INDEX(TableCell *cell) {
|
||||
unsigned i;
|
||||
size_t i;
|
||||
|
||||
assert(cell);
|
||||
|
||||
i = PTR_TO_UINT(cell);
|
||||
i = PTR_TO_SIZE(cell);
|
||||
assert(i > 0);
|
||||
|
||||
return i-1;
|
||||
@ -85,7 +85,7 @@ static size_t TABLE_CELL_TO_INDEX(TableCell *cell) {
|
||||
|
||||
static TableCell* TABLE_INDEX_TO_CELL(size_t index) {
|
||||
assert(index != (size_t) -1);
|
||||
return UINT_TO_PTR((unsigned) (index + 1));
|
||||
return SIZE_TO_PTR(index + 1);
|
||||
}
|
||||
|
||||
struct Table {
|
||||
|
@ -2560,7 +2560,7 @@ int json_buildv(JsonVariant **ret, va_list ap) {
|
||||
};
|
||||
|
||||
for (;;) {
|
||||
JsonVariant *add = NULL;
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *add = NULL;
|
||||
JsonStack *current;
|
||||
int command;
|
||||
|
||||
@ -2899,7 +2899,7 @@ int json_buildv(JsonVariant **ret, va_list ap) {
|
||||
goto finish;
|
||||
}
|
||||
|
||||
current->elements[current->n_elements++] = add;
|
||||
current->elements[current->n_elements++] = TAKE_PTR(add);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -418,8 +418,9 @@ static int whitelist_device(BPFProgram *prog, const char *path, const char *node
|
||||
if (!prog)
|
||||
return 0;
|
||||
|
||||
cgroup_bpf_whitelist_device(prog, S_ISCHR(st.st_mode) ? BPF_DEVCG_DEV_CHAR : BPF_DEVCG_DEV_BLOCK,
|
||||
major(st.st_rdev), minor(st.st_rdev), acc);
|
||||
return cgroup_bpf_whitelist_device(prog, S_ISCHR(st.st_mode) ? BPF_DEVCG_DEV_CHAR : BPF_DEVCG_DEV_BLOCK,
|
||||
major(st.st_rdev), minor(st.st_rdev), acc);
|
||||
|
||||
} else {
|
||||
char buf[2+DECIMAL_STR_MAX(dev_t)*2+2+4];
|
||||
|
||||
@ -431,11 +432,11 @@ static int whitelist_device(BPFProgram *prog, const char *path, const char *node
|
||||
|
||||
r = cg_set_attribute("devices", path, "devices.allow", buf);
|
||||
if (r < 0)
|
||||
log_full_errno(IN_SET(r, -ENOENT, -EROFS, -EINVAL, -EACCES) ? LOG_DEBUG : LOG_WARNING,
|
||||
r, "Failed to set devices.allow on %s: %m", path);
|
||||
}
|
||||
return log_full_errno(IN_SET(r, -ENOENT, -EROFS, -EINVAL, -EACCES) ? LOG_DEBUG : LOG_WARNING,
|
||||
r, "Failed to set devices.allow on %s: %m", path);
|
||||
|
||||
return r;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static int whitelist_major(BPFProgram *prog, const char *path, const char *name, char type, const char *acc) {
|
||||
@ -499,9 +500,9 @@ static int whitelist_major(BPFProgram *prog, const char *path, const char *name,
|
||||
if (!prog)
|
||||
continue;
|
||||
|
||||
cgroup_bpf_whitelist_major(prog,
|
||||
type == 'c' ? BPF_DEVCG_DEV_CHAR : BPF_DEVCG_DEV_BLOCK,
|
||||
maj, acc);
|
||||
(void) cgroup_bpf_whitelist_major(prog,
|
||||
type == 'c' ? BPF_DEVCG_DEV_CHAR : BPF_DEVCG_DEV_BLOCK,
|
||||
maj, acc);
|
||||
} else {
|
||||
char buf[2+DECIMAL_STR_MAX(unsigned)+3+4];
|
||||
|
||||
@ -1079,10 +1080,10 @@ static void cgroup_context_apply(
|
||||
const char *x, *y;
|
||||
|
||||
NULSTR_FOREACH_PAIR(x, y, auto_devices)
|
||||
whitelist_device(prog, path, x, y);
|
||||
(void) whitelist_device(prog, path, x, y);
|
||||
|
||||
/* PTS (/dev/pts) devices may not be duplicated, but accessed */
|
||||
whitelist_major(prog, path, "pts", 'c', "rw");
|
||||
(void) whitelist_major(prog, path, "pts", 'c', "rw");
|
||||
}
|
||||
|
||||
LIST_FOREACH(device_allow, a, c->device_allow) {
|
||||
@ -1102,11 +1103,11 @@ static void cgroup_context_apply(
|
||||
acc[k++] = 0;
|
||||
|
||||
if (path_startswith(a->path, "/dev/"))
|
||||
whitelist_device(prog, path, a->path, acc);
|
||||
(void) whitelist_device(prog, path, a->path, acc);
|
||||
else if ((val = startswith(a->path, "block-")))
|
||||
whitelist_major(prog, path, val, 'b', acc);
|
||||
(void) whitelist_major(prog, path, val, 'b', acc);
|
||||
else if ((val = startswith(a->path, "char-")))
|
||||
whitelist_major(prog, path, val, 'c', acc);
|
||||
(void) whitelist_major(prog, path, val, 'c', acc);
|
||||
else
|
||||
log_unit_debug(u, "Ignoring device %s while writing cgroup attribute.", a->path);
|
||||
}
|
||||
|
@ -280,8 +280,7 @@ int start_upload(Uploader *u,
|
||||
|
||||
static size_t fd_input_callback(void *buf, size_t size, size_t nmemb, void *userp) {
|
||||
Uploader *u = userp;
|
||||
|
||||
ssize_t r;
|
||||
ssize_t n;
|
||||
|
||||
assert(u);
|
||||
assert(nmemb < SSIZE_MAX / size);
|
||||
@ -289,21 +288,22 @@ static size_t fd_input_callback(void *buf, size_t size, size_t nmemb, void *user
|
||||
if (u->input < 0)
|
||||
return 0;
|
||||
|
||||
r = read(u->input, buf, size * nmemb);
|
||||
log_debug("%s: allowed %zu, read %zd", __func__, size*nmemb, r);
|
||||
assert(!size_multiply_overflow(size, nmemb));
|
||||
|
||||
if (r > 0)
|
||||
return r;
|
||||
n = read(u->input, buf, size * nmemb);
|
||||
log_debug("%s: allowed %zu, read %zd", __func__, size*nmemb, n);
|
||||
if (n > 0)
|
||||
return n;
|
||||
|
||||
u->uploading = false;
|
||||
if (r == 0) {
|
||||
log_debug("Reached EOF");
|
||||
close_fd_input(u);
|
||||
return 0;
|
||||
} else {
|
||||
if (n < 0) {
|
||||
log_error_errno(errno, "Aborting transfer after read error on input: %m.");
|
||||
return CURL_READFUNC_ABORT;
|
||||
}
|
||||
|
||||
log_debug("Reached EOF");
|
||||
close_fd_input(u);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void close_fd_input(Uploader *u) {
|
||||
|
@ -526,7 +526,7 @@ int server_open_audit(Server *s) {
|
||||
return 0;
|
||||
}
|
||||
} else
|
||||
fd_nonblock(s->audit_fd, 1);
|
||||
(void) fd_nonblock(s->audit_fd, true);
|
||||
|
||||
r = setsockopt(s->audit_fd, SOL_SOCKET, SO_PASSCRED, &one, sizeof(one));
|
||||
if (r < 0)
|
||||
|
@ -461,7 +461,7 @@ int server_open_native_socket(Server*s) {
|
||||
|
||||
(void) chmod(sa.un.sun_path, 0666);
|
||||
} else
|
||||
fd_nonblock(s->native_fd, 1);
|
||||
(void) fd_nonblock(s->native_fd, true);
|
||||
|
||||
r = setsockopt(s->native_fd, SOL_SOCKET, SO_PASSCRED, &one, sizeof(one));
|
||||
if (r < 0)
|
||||
|
@ -804,7 +804,7 @@ int server_open_stdout_socket(Server *s) {
|
||||
if (listen(s->stdout_fd, SOMAXCONN) < 0)
|
||||
return log_error_errno(errno, "listen(%s) failed: %m", sa.un.sun_path);
|
||||
} else
|
||||
fd_nonblock(s->stdout_fd, 1);
|
||||
(void) fd_nonblock(s->stdout_fd, true);
|
||||
|
||||
r = sd_event_add_io(s->event, &s->stdout_event_source, s->stdout_fd, EPOLLIN, stdout_stream_new, s);
|
||||
if (r < 0)
|
||||
|
@ -465,7 +465,7 @@ int server_open_syslog_socket(Server *s) {
|
||||
|
||||
(void) chmod(sa.un.sun_path, 0666);
|
||||
} else
|
||||
fd_nonblock(s->syslog_fd, 1);
|
||||
(void) fd_nonblock(s->syslog_fd, true);
|
||||
|
||||
r = setsockopt(s->syslog_fd, SOL_SOCKET, SO_PASSCRED, &one, sizeof(one));
|
||||
if (r < 0)
|
||||
|
@ -100,7 +100,7 @@ _public_ sd_event *sd_ndisc_get_event(sd_ndisc *nd) {
|
||||
return nd->event;
|
||||
}
|
||||
|
||||
static int ndisc_reset(sd_ndisc *nd) {
|
||||
static void ndisc_reset(sd_ndisc *nd) {
|
||||
assert(nd);
|
||||
|
||||
nd->timeout_event_source = sd_event_source_unref(nd->timeout_event_source);
|
||||
@ -108,8 +108,6 @@ static int ndisc_reset(sd_ndisc *nd) {
|
||||
nd->retransmit_time = 0;
|
||||
nd->recv_event_source = sd_event_source_unref(nd->recv_event_source);
|
||||
nd->fd = safe_close(nd->fd);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static sd_ndisc *ndisc_free(sd_ndisc *nd) {
|
||||
@ -301,7 +299,7 @@ static int ndisc_timeout(sd_event_source *s, uint64_t usec, void *userdata) {
|
||||
return 0;
|
||||
|
||||
fail:
|
||||
sd_ndisc_stop(nd);
|
||||
(void) sd_ndisc_stop(nd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1325,8 +1325,8 @@ static int process_forward(sd_event *event, PTYForward **forward, int master, PT
|
||||
log_info("Connected to machine %s. Press ^] three times within 1s to exit session.", name);
|
||||
}
|
||||
|
||||
sd_event_add_signal(event, NULL, SIGINT, NULL, NULL);
|
||||
sd_event_add_signal(event, NULL, SIGTERM, NULL, NULL);
|
||||
(void) sd_event_add_signal(event, NULL, SIGINT, NULL, NULL);
|
||||
(void) sd_event_add_signal(event, NULL, SIGTERM, NULL, NULL);
|
||||
|
||||
r = pty_forward_new(event, master, flags, forward);
|
||||
if (r < 0)
|
||||
@ -1983,8 +1983,8 @@ static int transfer_image_common(sd_bus *bus, sd_bus_message *m) {
|
||||
if (!arg_quiet)
|
||||
log_info("Enqueued transfer job %u. Press C-c to continue download in background.", id);
|
||||
|
||||
sd_event_add_signal(event, NULL, SIGINT, transfer_signal_handler, UINT32_TO_PTR(id));
|
||||
sd_event_add_signal(event, NULL, SIGTERM, transfer_signal_handler, UINT32_TO_PTR(id));
|
||||
(void) sd_event_add_signal(event, NULL, SIGINT, transfer_signal_handler, UINT32_TO_PTR(id));
|
||||
(void) sd_event_add_signal(event, NULL, SIGTERM, transfer_signal_handler, UINT32_TO_PTR(id));
|
||||
|
||||
r = sd_event_loop(event);
|
||||
if (r < 0)
|
||||
|
@ -263,8 +263,8 @@ int manager_new(Manager **ret, char **interfaces, char **ignore, usec_t timeout)
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
sd_event_add_signal(m->event, NULL, SIGTERM, NULL, NULL);
|
||||
sd_event_add_signal(m->event, NULL, SIGINT, NULL, NULL);
|
||||
(void) sd_event_add_signal(m->event, NULL, SIGTERM, NULL, NULL);
|
||||
(void) sd_event_add_signal(m->event, NULL, SIGINT, NULL, NULL);
|
||||
|
||||
if (timeout > 0) {
|
||||
usec_t usec;
|
||||
|
@ -455,6 +455,9 @@ int efi_get_boot_option(
|
||||
/* Sub-Type 4 – File Path */
|
||||
if (dpath->sub_type == MEDIA_FILEPATH_DP && !p && path) {
|
||||
p = utf16_to_utf8(dpath->path, dpath->length-4);
|
||||
if (!p)
|
||||
return -ENOMEM;
|
||||
|
||||
efi_tilt_backslashes(p);
|
||||
continue;
|
||||
}
|
||||
|
@ -105,7 +105,7 @@ int test_main(int argc, char *argv[], void *userdata) {
|
||||
"some values may be different, or not available at a simulation run.\n"
|
||||
"\n");
|
||||
|
||||
sigprocmask(SIG_SETMASK, NULL, &sigmask_orig);
|
||||
assert_se(sigprocmask(SIG_SETMASK, NULL, &sigmask_orig) >= 0);
|
||||
|
||||
udev_builtin_init();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user