[systemd-commits] 4 commits - src/shared src/udev
Tom Gundersen
tomegun at kemper.freedesktop.org
Wed Sep 17 13:20:17 PDT 2014
src/shared/conf-parser.h | 4 ++
src/udev/udev-event.c | 69 +++++++++++++++++++++++------------------------
2 files changed, 39 insertions(+), 34 deletions(-)
New commits:
commit 83e341a637b75f7f592a5dc717c34d8b67ed4ffa
Author: Tom Gundersen <teg at jklm.no>
Date: Wed Sep 17 22:17:53 2014 +0200
shared: conf-parser
Check memory allocation. Found by Coverity.
Fixes CID #1237644.
diff --git a/src/shared/conf-parser.h b/src/shared/conf-parser.h
index a17dde9..9418515 100644
--- a/src/shared/conf-parser.h
+++ b/src/shared/conf-parser.h
@@ -179,6 +179,9 @@ int log_syntax_internal(const char *unit, int level,
assert(data); \
\
xs = new0(type, 1); \
+ if(!xs) \
+ return -ENOMEM; \
+ \
*xs = invalid; \
\
FOREACH_WORD(word, l, rvalue, state) { \
@@ -211,6 +214,7 @@ int log_syntax_internal(const char *unit, int level,
xs = realloc(xs, (++i + 1) * sizeof(type)); \
if (!xs) \
return -ENOMEM; \
+ \
*(xs + i) = invalid; \
} \
\
commit 19c784c414e6f2b35a268034905e1db226e905f6
Author: Tom Gundersen <teg at jklm.no>
Date: Wed Sep 17 21:53:20 2014 +0200
udev: event - modernize spawn_exec()
diff --git a/src/udev/udev-event.c b/src/udev/udev-event.c
index c8b1420..dc1f682 100644
--- a/src/udev/udev-event.c
+++ b/src/udev/udev-event.c
@@ -376,8 +376,7 @@ out:
static int spawn_exec(struct udev_event *event,
const char *cmd, char *const argv[], char **envp, const sigset_t *sigmask,
int fd_stdout, int fd_stderr) {
- int err;
- int fd;
+ _cleanup_close_ int fd = -1;
/* discard child output or connect to pipe */
fd = open("/dev/null", O_RDWR);
@@ -387,19 +386,17 @@ static int spawn_exec(struct udev_event *event,
dup2(fd, STDOUT_FILENO);
if (fd_stderr < 0)
dup2(fd, STDERR_FILENO);
- close(fd);
- } else {
+ } else
log_error("open /dev/null failed: %m");
- }
/* connect pipes to std{out,err} */
if (fd_stdout >= 0) {
dup2(fd_stdout, STDOUT_FILENO);
- close(fd_stdout);
+ safe_close(fd_stdout);
}
if (fd_stderr >= 0) {
dup2(fd_stderr, STDERR_FILENO);
- close(fd_stderr);
+ safe_close(fd_stderr);
}
/* terminate child in case parent goes away */
@@ -412,9 +409,9 @@ static int spawn_exec(struct udev_event *event,
execve(argv[0], argv, envp);
/* exec failed */
- err = -errno;
log_error("failed to execute '%s' '%s': %m", argv[0], cmd);
- return err;
+
+ return -errno;
}
static void spawn_read(struct udev_event *event,
commit 3f796750b192e62701e91a95f85389f876d1059b
Author: Tom Gundersen <teg at jklm.no>
Date: Wed Sep 17 21:44:56 2014 +0200
udev: event - explicitly don't read() from invalid fd
This fixes CID #1237641.
diff --git a/src/udev/udev-event.c b/src/udev/udev-event.c
index 6b8b5a8..c8b1420 100644
--- a/src/udev/udev-event.c
+++ b/src/udev/udev-event.c
@@ -494,6 +494,9 @@ static void spawn_read(struct udev_event *event,
for (i = 0; i < fdcount; i++) {
int *fd = (int *)ev[i].data.ptr;
+ if (*fd < 0)
+ continue;
+
if (ev[i].events & EPOLLIN) {
ssize_t count;
char buf[4096];
commit 4cd5d5adb6a573d8ffb336b82325e5f2bb188381
Author: Tom Gundersen <teg at jklm.no>
Date: Wed Sep 17 21:43:57 2014 +0200
udev: event - modernize spawn_read()
diff --git a/src/udev/udev-event.c b/src/udev/udev-event.c
index e8d6676..6b8b5a8 100644
--- a/src/udev/udev-event.c
+++ b/src/udev/udev-event.c
@@ -422,9 +422,17 @@ static void spawn_read(struct udev_event *event,
const char *cmd,
int fd_stdout, int fd_stderr,
char *result, size_t ressize) {
+ _cleanup_close_ int fd_ep = -1;
+ struct epoll_event ep_outpipe = {
+ .events = EPOLLIN,
+ .data.ptr = &fd_stdout,
+ };
+ struct epoll_event ep_errpipe = {
+ .events = EPOLLIN,
+ .data.ptr = &fd_stderr,
+ };
size_t respos = 0;
- int fd_ep = -1;
- struct epoll_event ep_outpipe, ep_errpipe;
+ int r;
/* read from child if requested */
if (fd_stdout < 0 && fd_stderr < 0)
@@ -433,26 +441,22 @@ static void spawn_read(struct udev_event *event,
fd_ep = epoll_create1(EPOLL_CLOEXEC);
if (fd_ep < 0) {
log_error("error creating epoll fd: %m");
- goto out;
+ return;
}
if (fd_stdout >= 0) {
- memzero(&ep_outpipe, sizeof(struct epoll_event));
- ep_outpipe.events = EPOLLIN;
- ep_outpipe.data.ptr = &fd_stdout;
- if (epoll_ctl(fd_ep, EPOLL_CTL_ADD, fd_stdout, &ep_outpipe) < 0) {
- log_error("fail to add fd to epoll: %m");
- goto out;
+ r = epoll_ctl(fd_ep, EPOLL_CTL_ADD, fd_stdout, &ep_outpipe);
+ if (r < 0) {
+ log_error("fail to add stdout fd to epoll: %m");
+ return;
}
}
if (fd_stderr >= 0) {
- memzero(&ep_errpipe, sizeof(struct epoll_event));
- ep_errpipe.events = EPOLLIN;
- ep_errpipe.data.ptr = &fd_stderr;
- if (epoll_ctl(fd_ep, EPOLL_CTL_ADD, fd_stderr, &ep_errpipe) < 0) {
- log_error("fail to add fd to epoll: %m");
- goto out;
+ r = epoll_ctl(fd_ep, EPOLL_CTL_ADD, fd_stderr, &ep_errpipe);
+ if (r < 0) {
+ log_error("fail to add stderr fd to epoll: %m");
+ return;
}
}
@@ -469,7 +473,7 @@ static void spawn_read(struct udev_event *event,
age_usec = now(CLOCK_MONOTONIC) - event->birth_usec;
if (age_usec >= timeout_usec) {
log_error("timeout '%s'", cmd);
- goto out;
+ return;
}
timeout = ((timeout_usec - age_usec) / USEC_PER_MSEC) + MSEC_PER_SEC;
} else {
@@ -481,11 +485,10 @@ static void spawn_read(struct udev_event *event,
if (errno == EINTR)
continue;
log_error("failed to poll: %m");
- goto out;
- }
- if (fdcount == 0) {
+ return;
+ } else if (fdcount == 0) {
log_error("timeout '%s'", cmd);
- goto out;
+ return;
}
for (i = 0; i < fdcount; i++) {
@@ -522,9 +525,10 @@ static void spawn_read(struct udev_event *event,
}
}
} else if (ev[i].events & EPOLLHUP) {
- if (epoll_ctl(fd_ep, EPOLL_CTL_DEL, *fd, NULL) < 0) {
+ r = epoll_ctl(fd_ep, EPOLL_CTL_DEL, *fd, NULL);
+ if (r < 0) {
log_error("failed to remove fd from epoll: %m");
- goto out;
+ return;
}
*fd = -1;
}
@@ -534,9 +538,6 @@ static void spawn_read(struct udev_event *event,
/* return the child's stdout string */
if (result != NULL)
result[respos] = '\0';
-out:
- if (fd_ep >= 0)
- close(fd_ep);
}
static int spawn_wait(struct udev_event *event,
More information about the systemd-commits
mailing list