mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-03-10 00:58:20 +03:00
Merge pull request #10356 from dtardon/covscan
assorted coverity/clang fixes
This commit is contained in:
commit
a6ee956610
@ -52,8 +52,11 @@ static inline void freep(void *p) {
|
|||||||
|
|
||||||
#define _cleanup_free_ _cleanup_(freep)
|
#define _cleanup_free_ _cleanup_(freep)
|
||||||
|
|
||||||
|
/* Checks the size arguments of allocation functions for overflow in multiplication. In addition, checks if either of
|
||||||
|
* them is 0; that is almost certainly an error (e.g., an overflow in computing _need_), so it's better to fail (and
|
||||||
|
* we cannot leave this check to malloc, because the behavior of malloc(0) is impl. specific). */
|
||||||
static inline bool size_multiply_overflow(size_t size, size_t need) {
|
static inline bool size_multiply_overflow(size_t size, size_t need) {
|
||||||
return _unlikely_(need != 0 && size > (SIZE_MAX / need));
|
return _unlikely_(need == 0 || size == 0 || size > (SIZE_MAX / need));
|
||||||
}
|
}
|
||||||
|
|
||||||
_malloc_ _alloc_(1, 2) static inline void *malloc_multiply(size_t size, size_t need) {
|
_malloc_ _alloc_(1, 2) static inline void *malloc_multiply(size_t size, size_t need) {
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
#define EFI_CONTROL_PRESSED (EFI_RIGHT_CONTROL_PRESSED|EFI_LEFT_CONTROL_PRESSED)
|
#define EFI_CONTROL_PRESSED (EFI_RIGHT_CONTROL_PRESSED|EFI_LEFT_CONTROL_PRESSED)
|
||||||
#define EFI_ALT_PRESSED (EFI_RIGHT_ALT_PRESSED|EFI_LEFT_ALT_PRESSED)
|
#define EFI_ALT_PRESSED (EFI_RIGHT_ALT_PRESSED|EFI_LEFT_ALT_PRESSED)
|
||||||
#define KEYPRESS(keys, scan, uni) ((((UINT64)keys) << 32) | ((scan) << 16) | (uni))
|
#define KEYPRESS(keys, scan, uni) ((((UINT64)keys) << 32) | (((UINT64)scan) << 16) | (uni))
|
||||||
#define KEYCHAR(k) ((k) & 0xffff)
|
#define KEYCHAR(k) ((k) & 0xffff)
|
||||||
#define CHAR_CTRL(c) ((c) - 'a' + 1)
|
#define CHAR_CTRL(c) ((c) - 'a' + 1)
|
||||||
|
|
||||||
|
@ -892,7 +892,7 @@ static int manager_setup_notify(Manager *m) {
|
|||||||
(void) mkdir_parents_label(m->notify_socket, 0755);
|
(void) mkdir_parents_label(m->notify_socket, 0755);
|
||||||
(void) unlink(m->notify_socket);
|
(void) unlink(m->notify_socket);
|
||||||
|
|
||||||
strncpy(sa.un.sun_path, m->notify_socket, sizeof(sa.un.sun_path)-1);
|
strncpy(sa.un.sun_path, m->notify_socket, sizeof(sa.un.sun_path));
|
||||||
r = bind(fd, &sa.sa, SOCKADDR_UN_LEN(sa.un));
|
r = bind(fd, &sa.sa, SOCKADDR_UN_LEN(sa.un));
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return log_error_errno(errno, "bind(%s) failed: %m", sa.un.sun_path);
|
return log_error_errno(errno, "bind(%s) failed: %m", sa.un.sun_path);
|
||||||
|
@ -1846,6 +1846,9 @@ static int journal_file_append_entry_internal(
|
|||||||
void journal_file_post_change(JournalFile *f) {
|
void journal_file_post_change(JournalFile *f) {
|
||||||
assert(f);
|
assert(f);
|
||||||
|
|
||||||
|
if (f->fd < 0)
|
||||||
|
return;
|
||||||
|
|
||||||
/* inotify() does not receive IN_MODIFY events from file
|
/* inotify() does not receive IN_MODIFY events from file
|
||||||
* accesses done via mmap(). After each access we hence
|
* accesses done via mmap(). After each access we hence
|
||||||
* trigger IN_MODIFY by truncating the journal file to its
|
* trigger IN_MODIFY by truncating the journal file to its
|
||||||
|
@ -2157,6 +2157,7 @@ static int method_cancel_scheduled_shutdown(sd_bus_message *message, void *userd
|
|||||||
|
|
||||||
if (cancelled && m->enable_wall_messages) {
|
if (cancelled && m->enable_wall_messages) {
|
||||||
_cleanup_(sd_bus_creds_unrefp) sd_bus_creds *creds = NULL;
|
_cleanup_(sd_bus_creds_unrefp) sd_bus_creds *creds = NULL;
|
||||||
|
_cleanup_free_ char *username = NULL;
|
||||||
const char *tty = NULL;
|
const char *tty = NULL;
|
||||||
uid_t uid = 0;
|
uid_t uid = 0;
|
||||||
int r;
|
int r;
|
||||||
@ -2167,8 +2168,9 @@ static int method_cancel_scheduled_shutdown(sd_bus_message *message, void *userd
|
|||||||
(void) sd_bus_creds_get_tty(creds, &tty);
|
(void) sd_bus_creds_get_tty(creds, &tty);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
username = uid_to_name(uid);
|
||||||
utmp_wall("The system shutdown has been cancelled",
|
utmp_wall("The system shutdown has been cancelled",
|
||||||
uid_to_name(uid), tty, logind_wall_tty_filter, m);
|
username, tty, logind_wall_tty_filter, m);
|
||||||
}
|
}
|
||||||
|
|
||||||
return sd_bus_reply_method_return(message, "b", cancelled);
|
return sd_bus_reply_method_return(message, "b", cancelled);
|
||||||
|
@ -61,7 +61,7 @@ bool logind_wall_tty_filter(const char *tty, void *userdata) {
|
|||||||
|
|
||||||
static int warn_wall(Manager *m, usec_t n) {
|
static int warn_wall(Manager *m, usec_t n) {
|
||||||
char date[FORMAT_TIMESTAMP_MAX] = {};
|
char date[FORMAT_TIMESTAMP_MAX] = {};
|
||||||
_cleanup_free_ char *l = NULL;
|
_cleanup_free_ char *l = NULL, *username = NULL;
|
||||||
usec_t left;
|
usec_t left;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
@ -83,8 +83,8 @@ static int warn_wall(Manager *m, usec_t n) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
utmp_wall(l, uid_to_name(m->scheduled_shutdown_uid),
|
username = uid_to_name(m->scheduled_shutdown_uid);
|
||||||
m->scheduled_shutdown_tty, logind_wall_tty_filter, m);
|
utmp_wall(l, username, m->scheduled_shutdown_tty, logind_wall_tty_filter, m);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -160,7 +160,7 @@ static int get_seat_from_display(const char *display, const char **seat, uint32_
|
|||||||
r = socket_from_display(display, &p);
|
r = socket_from_display(display, &p);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
strncpy(sa.un.sun_path, p, sizeof(sa.un.sun_path)-1);
|
strncpy(sa.un.sun_path, p, sizeof(sa.un.sun_path));
|
||||||
|
|
||||||
fd = socket(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC, 0);
|
fd = socket(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC, 0);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
|
@ -2826,7 +2826,7 @@ static int setup_sd_notify_child(void) {
|
|||||||
(void) mkdir_parents(NSPAWN_NOTIFY_SOCKET_PATH, 0755);
|
(void) mkdir_parents(NSPAWN_NOTIFY_SOCKET_PATH, 0755);
|
||||||
(void) unlink(NSPAWN_NOTIFY_SOCKET_PATH);
|
(void) unlink(NSPAWN_NOTIFY_SOCKET_PATH);
|
||||||
|
|
||||||
strncpy(sa.un.sun_path, NSPAWN_NOTIFY_SOCKET_PATH, sizeof(sa.un.sun_path)-1);
|
strncpy(sa.un.sun_path, NSPAWN_NOTIFY_SOCKET_PATH, sizeof(sa.un.sun_path));
|
||||||
r = bind(fd, &sa.sa, SOCKADDR_UN_LEN(sa.un));
|
r = bind(fd, &sa.sa, SOCKADDR_UN_LEN(sa.un));
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
safe_close(fd);
|
safe_close(fd);
|
||||||
|
@ -231,7 +231,7 @@ int dissect_image(
|
|||||||
.node = TAKE_PTR(n),
|
.node = TAKE_PTR(n),
|
||||||
};
|
};
|
||||||
|
|
||||||
m->encrypted = streq(fstype, "crypto_LUKS");
|
m->encrypted = streq_ptr(fstype, "crypto_LUKS");
|
||||||
|
|
||||||
*ret = TAKE_PTR(m);
|
*ret = TAKE_PTR(m);
|
||||||
|
|
||||||
|
@ -412,9 +412,13 @@ int efi_get_boot_option(
|
|||||||
|
|
||||||
if (header->path_len > 0) {
|
if (header->path_len > 0) {
|
||||||
uint8_t *dbuf;
|
uint8_t *dbuf;
|
||||||
size_t dnext;
|
size_t dnext, doff;
|
||||||
|
|
||||||
|
doff = offsetof(struct boot_option, title) + title_size;
|
||||||
|
dbuf = buf + doff;
|
||||||
|
if (header->path_len > l - doff)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
dbuf = buf + offsetof(struct boot_option, title) + title_size;
|
|
||||||
dnext = 0;
|
dnext = 0;
|
||||||
while (dnext < header->path_len) {
|
while (dnext < header->path_len) {
|
||||||
struct device_path *dpath;
|
struct device_path *dpath;
|
||||||
|
@ -211,13 +211,16 @@ fail:
|
|||||||
int fdset_close_others(FDSet *fds) {
|
int fdset_close_others(FDSet *fds) {
|
||||||
void *e;
|
void *e;
|
||||||
Iterator i;
|
Iterator i;
|
||||||
int *a;
|
int *a = NULL;
|
||||||
size_t j = 0, m;
|
size_t j = 0, m;
|
||||||
|
|
||||||
m = fdset_size(fds);
|
m = fdset_size(fds);
|
||||||
a = newa(int, m);
|
|
||||||
SET_FOREACH(e, MAKE_SET(fds), i)
|
if (m > 0) {
|
||||||
a[j++] = PTR_TO_FD(e);
|
a = newa(int, m);
|
||||||
|
SET_FOREACH(e, MAKE_SET(fds), i)
|
||||||
|
a[j++] = PTR_TO_FD(e);
|
||||||
|
}
|
||||||
|
|
||||||
assert(j == m);
|
assert(j == m);
|
||||||
|
|
||||||
|
@ -50,8 +50,14 @@ static int entry_fill_basics(
|
|||||||
entry->ip.proto = protocol;
|
entry->ip.proto = protocol;
|
||||||
|
|
||||||
if (in_interface) {
|
if (in_interface) {
|
||||||
|
size_t l;
|
||||||
|
|
||||||
|
l = strlen(in_interface);
|
||||||
|
assert(l < sizeof entry->ip.iniface);
|
||||||
|
assert(l < sizeof entry->ip.iniface_mask);
|
||||||
|
|
||||||
strcpy(entry->ip.iniface, in_interface);
|
strcpy(entry->ip.iniface, in_interface);
|
||||||
memset(entry->ip.iniface_mask, 0xFF, strlen(in_interface)+1);
|
memset(entry->ip.iniface_mask, 0xFF, l + 1);
|
||||||
}
|
}
|
||||||
if (source) {
|
if (source) {
|
||||||
entry->ip.src = source->in;
|
entry->ip.src = source->in;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user