mirror of
https://github.com/systemd/systemd.git
synced 2025-03-31 14:50:15 +03:00
Merge pull request #5390 from keszybz/coverity
Clarifications to make coverity happy
This commit is contained in:
commit
1ebfd03bd9
@ -1144,11 +1144,13 @@ static int setup_pam(
|
||||
|
||||
/* Tell the parent that our setup is done. This is especially
|
||||
* important regarding dropping privileges. Otherwise, unit
|
||||
* setup might race against our setresuid(2) call. */
|
||||
barrier_place(&barrier);
|
||||
* setup might race against our setresuid(2) call.
|
||||
*
|
||||
* If the parent aborted, we'll detect this below, hence ignore
|
||||
* return failure here. */
|
||||
(void) barrier_place(&barrier);
|
||||
|
||||
/* Check if our parent process might already have
|
||||
* died? */
|
||||
/* Check if our parent process might already have died? */
|
||||
if (getppid() == parent_pid) {
|
||||
sigset_t ss;
|
||||
|
||||
|
@ -213,7 +213,8 @@ static int killall(int sig, Set *pids, bool send_sighup) {
|
||||
|
||||
|
||||
if (get_ctty_devnr(pid, NULL) >= 0)
|
||||
kill(pid, SIGHUP);
|
||||
/* it's OK if the process is gone, just ignore the result */
|
||||
(void) kill(pid, SIGHUP);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -449,8 +449,11 @@ static int transfer_start(Transfer *t) {
|
||||
|
||||
stdio_unset_cloexec();
|
||||
|
||||
setenv("SYSTEMD_LOG_TARGET", "console-prefixed", 1);
|
||||
setenv("NOTIFY_SOCKET", "/run/systemd/import/notify", 1);
|
||||
if (setenv("SYSTEMD_LOG_TARGET", "console-prefixed", 1) < 0 ||
|
||||
setenv("NOTIFY_SOCKET", "/run/systemd/import/notify", 1) < 0) {
|
||||
log_error_errno(errno, "setenv() failed: %m");
|
||||
_exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (IN_SET(t->type, TRANSFER_IMPORT_TAR, TRANSFER_IMPORT_RAW))
|
||||
cmd[k++] = SYSTEMD_IMPORT_PATH;
|
||||
|
@ -1859,8 +1859,7 @@ _public_ int sd_device_set_sysattr_value(sd_device *device, const char *sysattr,
|
||||
_cleanup_free_ char *value = NULL;
|
||||
const char *syspath;
|
||||
char *path;
|
||||
struct stat statbuf;
|
||||
size_t value_len = 0;
|
||||
size_t len = 0;
|
||||
ssize_t size;
|
||||
int r;
|
||||
|
||||
@ -1878,8 +1877,14 @@ _public_ int sd_device_set_sysattr_value(sd_device *device, const char *sysattr,
|
||||
return r;
|
||||
|
||||
path = strjoina(syspath, "/", sysattr);
|
||||
r = lstat(path, &statbuf);
|
||||
if (r < 0) {
|
||||
|
||||
fd = open(path, O_WRONLY | O_CLOEXEC | O_NOFOLLOW);
|
||||
if (fd < 0) {
|
||||
if (errno == ELOOP)
|
||||
return -EINVAL;
|
||||
if (errno == EISDIR)
|
||||
return -EISDIR;
|
||||
|
||||
value = strdup("");
|
||||
if (!value)
|
||||
return -ENOMEM;
|
||||
@ -1891,46 +1896,30 @@ _public_ int sd_device_set_sysattr_value(sd_device *device, const char *sysattr,
|
||||
return -ENXIO;
|
||||
}
|
||||
|
||||
if (S_ISLNK(statbuf.st_mode))
|
||||
return -EINVAL;
|
||||
|
||||
/* skip directories */
|
||||
if (S_ISDIR(statbuf.st_mode))
|
||||
return -EISDIR;
|
||||
|
||||
/* skip non-readable files */
|
||||
if ((statbuf.st_mode & S_IRUSR) == 0)
|
||||
return -EACCES;
|
||||
|
||||
value_len = strlen(_value);
|
||||
len = strlen(_value);
|
||||
|
||||
/* drop trailing newlines */
|
||||
while (value_len > 0 && _value[value_len - 1] == '\n')
|
||||
_value[--value_len] = '\0';
|
||||
while (len > 0 && _value[len - 1] == '\n')
|
||||
len --;
|
||||
|
||||
/* value length is limited to 4k */
|
||||
if (value_len > 4096)
|
||||
if (len > 4096)
|
||||
return -EINVAL;
|
||||
|
||||
fd = open(path, O_WRONLY | O_CLOEXEC);
|
||||
if (fd < 0)
|
||||
return -errno;
|
||||
|
||||
value = strdup(_value);
|
||||
value = strndup(_value, len);
|
||||
if (!value)
|
||||
return -ENOMEM;
|
||||
|
||||
size = write(fd, value, value_len);
|
||||
size = write(fd, value, len);
|
||||
if (size < 0)
|
||||
return -errno;
|
||||
|
||||
if ((size_t)size != value_len)
|
||||
if ((size_t)size != len)
|
||||
return -EIO;
|
||||
|
||||
r = device_add_sysattr_value(device, sysattr, value);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
value = NULL;
|
||||
|
||||
return 0;
|
||||
|
@ -379,7 +379,8 @@ int seat_read_active_vt(Seat *s) {
|
||||
if (!seat_has_vts(s))
|
||||
return 0;
|
||||
|
||||
lseek(s->manager->console_active_fd, SEEK_SET, 0);
|
||||
if (lseek(s->manager->console_active_fd, SEEK_SET, 0) < 0)
|
||||
return log_error_errno(errno, "lseek on console_active_fd failed: %m");
|
||||
|
||||
k = read(s->manager->console_active_fd, t, sizeof(t)-1);
|
||||
if (k <= 0) {
|
||||
@ -396,10 +397,8 @@ int seat_read_active_vt(Seat *s) {
|
||||
}
|
||||
|
||||
r = safe_atou(t+3, &vtnr);
|
||||
if (r < 0) {
|
||||
log_error("Failed to parse VT number %s", t+3);
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to parse VT number \"%s\": %m", t+3);
|
||||
|
||||
if (!vtnr) {
|
||||
log_error("VT number invalid: %s", t+3);
|
||||
|
@ -76,8 +76,11 @@ static int entry_fill_basics(
|
||||
}
|
||||
|
||||
if (out_interface) {
|
||||
size_t l = strlen(out_interface);
|
||||
assert(l < sizeof entry->ip.outiface && l < sizeof entry->ip.outiface_mask);
|
||||
|
||||
strcpy(entry->ip.outiface, out_interface);
|
||||
memset(entry->ip.outiface_mask, 0xFF, strlen(out_interface)+1);
|
||||
memset(entry->ip.outiface_mask, 0xFF, l + 1);
|
||||
}
|
||||
if (destination) {
|
||||
entry->ip.dst = destination->in;
|
||||
|
@ -104,7 +104,8 @@ int pager_open(bool no_pager, bool jump_to_end) {
|
||||
less_opts = "FRSXMK";
|
||||
if (jump_to_end)
|
||||
less_opts = strjoina(less_opts, " +G");
|
||||
setenv("LESS", less_opts, 1);
|
||||
if (setenv("LESS", less_opts, 1) < 0)
|
||||
_exit(EXIT_FAILURE);
|
||||
|
||||
/* Initialize a good charset for less. This is
|
||||
* particularly important if we output UTF-8
|
||||
@ -112,8 +113,9 @@ int pager_open(bool no_pager, bool jump_to_end) {
|
||||
less_charset = getenv("SYSTEMD_LESSCHARSET");
|
||||
if (!less_charset && is_locale_utf8())
|
||||
less_charset = "utf-8";
|
||||
if (less_charset)
|
||||
setenv("LESSCHARSET", less_charset, 1);
|
||||
if (less_charset &&
|
||||
setenv("LESSCHARSET", less_charset, 1) < 0)
|
||||
_exit(EXIT_FAILURE);
|
||||
|
||||
/* Make sure the pager goes away when the parent dies */
|
||||
if (prctl(PR_SET_PDEATHSIG, SIGTERM) < 0)
|
||||
|
Loading…
x
Reference in New Issue
Block a user