Merge pull request #10356 from dtardon/covscan

assorted coverity/clang fixes
This commit is contained in:
Lennart Poettering 2018-10-12 18:43:04 +02:00 committed by GitHub
commit a6ee956610
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 38 additions and 17 deletions

View File

@ -52,8 +52,11 @@ static inline void freep(void *p) {
#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) {
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) {

View File

@ -9,7 +9,7 @@
#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 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 CHAR_CTRL(c) ((c) - 'a' + 1)

View File

@ -892,7 +892,7 @@ static int manager_setup_notify(Manager *m) {
(void) mkdir_parents_label(m->notify_socket, 0755);
(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));
if (r < 0)
return log_error_errno(errno, "bind(%s) failed: %m", sa.un.sun_path);

View File

@ -1846,6 +1846,9 @@ static int journal_file_append_entry_internal(
void journal_file_post_change(JournalFile *f) {
assert(f);
if (f->fd < 0)
return;
/* inotify() does not receive IN_MODIFY events from file
* accesses done via mmap(). After each access we hence
* trigger IN_MODIFY by truncating the journal file to its

View File

@ -2157,6 +2157,7 @@ static int method_cancel_scheduled_shutdown(sd_bus_message *message, void *userd
if (cancelled && m->enable_wall_messages) {
_cleanup_(sd_bus_creds_unrefp) sd_bus_creds *creds = NULL;
_cleanup_free_ char *username = NULL;
const char *tty = NULL;
uid_t uid = 0;
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);
}
username = uid_to_name(uid);
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);

View File

@ -61,7 +61,7 @@ bool logind_wall_tty_filter(const char *tty, void *userdata) {
static int warn_wall(Manager *m, usec_t n) {
char date[FORMAT_TIMESTAMP_MAX] = {};
_cleanup_free_ char *l = NULL;
_cleanup_free_ char *l = NULL, *username = NULL;
usec_t left;
int r;
@ -83,8 +83,8 @@ static int warn_wall(Manager *m, usec_t n) {
return 0;
}
utmp_wall(l, uid_to_name(m->scheduled_shutdown_uid),
m->scheduled_shutdown_tty, logind_wall_tty_filter, m);
username = uid_to_name(m->scheduled_shutdown_uid);
utmp_wall(l, username, m->scheduled_shutdown_tty, logind_wall_tty_filter, m);
return 1;
}

View File

@ -160,7 +160,7 @@ static int get_seat_from_display(const char *display, const char **seat, uint32_
r = socket_from_display(display, &p);
if (r < 0)
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);
if (fd < 0)

View File

@ -2826,7 +2826,7 @@ static int setup_sd_notify_child(void) {
(void) mkdir_parents(NSPAWN_NOTIFY_SOCKET_PATH, 0755);
(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));
if (r < 0) {
safe_close(fd);

View File

@ -231,7 +231,7 @@ int dissect_image(
.node = TAKE_PTR(n),
};
m->encrypted = streq(fstype, "crypto_LUKS");
m->encrypted = streq_ptr(fstype, "crypto_LUKS");
*ret = TAKE_PTR(m);

View File

@ -412,9 +412,13 @@ int efi_get_boot_option(
if (header->path_len > 0) {
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;
while (dnext < header->path_len) {
struct device_path *dpath;

View File

@ -211,13 +211,16 @@ fail:
int fdset_close_others(FDSet *fds) {
void *e;
Iterator i;
int *a;
int *a = NULL;
size_t j = 0, m;
m = fdset_size(fds);
a = newa(int, m);
SET_FOREACH(e, MAKE_SET(fds), i)
a[j++] = PTR_TO_FD(e);
if (m > 0) {
a = newa(int, m);
SET_FOREACH(e, MAKE_SET(fds), i)
a[j++] = PTR_TO_FD(e);
}
assert(j == m);

View File

@ -50,8 +50,14 @@ static int entry_fill_basics(
entry->ip.proto = protocol;
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);
memset(entry->ip.iniface_mask, 0xFF, strlen(in_interface)+1);
memset(entry->ip.iniface_mask, 0xFF, l + 1);
}
if (source) {
entry->ip.src = source->in;