|
|
76a39a |
From 4be4813262b3b57a95a5f3ce909d30741aa3ac72 Mon Sep 17 00:00:00 2001
|
|
|
76a39a |
From: =?UTF-8?q?Jan=20Stan=C4=9Bk?= <jstanek@redhat.com>
|
|
|
76a39a |
Date: Fri, 9 Apr 2021 16:47:33 +0200
|
|
|
76a39a |
Subject: [PATCH] Address issues raised by static analysis
|
|
|
76a39a |
MIME-Version: 1.0
|
|
|
76a39a |
Content-Type: text/plain; charset=UTF-8
|
|
|
76a39a |
Content-Transfer-Encoding: 8bit
|
|
|
76a39a |
|
|
|
76a39a |
Signed-off-by: Jan Staněk <jstanek@redhat.com>
|
|
|
76a39a |
---
|
|
|
76a39a |
at.c | 22 ++++++++++++++++++----
|
|
|
76a39a |
daemon.c | 21 ++++++++++++++-------
|
|
|
76a39a |
2 files changed, 32 insertions(+), 11 deletions(-)
|
|
|
76a39a |
|
|
|
76a39a |
diff --git a/at.c b/at.c
|
|
|
76a39a |
index df55dc9..0c74e2e 100644
|
|
|
76a39a |
--- a/at.c
|
|
|
76a39a |
+++ b/at.c
|
|
|
76a39a |
@@ -545,17 +545,27 @@ writefile(time_t runtimer, char queue)
|
|
|
76a39a |
return;
|
|
|
76a39a |
}
|
|
|
76a39a |
|
|
|
76a39a |
- if (fstat(fd, &statbuf) == -1)
|
|
|
76a39a |
+ if (fstat(fd, &statbuf) == -1) {
|
|
|
76a39a |
+ close(fd);
|
|
|
76a39a |
return;
|
|
|
76a39a |
+ }
|
|
|
76a39a |
if ((statbuf.st_uid != 0) || !S_ISREG(statbuf.st_mode) ||
|
|
|
76a39a |
- (statbuf.st_mode & (S_IWGRP | S_IWOTH)))
|
|
|
76a39a |
+ (statbuf.st_mode & (S_IWGRP | S_IWOTH))) {
|
|
|
76a39a |
+ close(fd);
|
|
|
76a39a |
return;
|
|
|
76a39a |
+ }
|
|
|
76a39a |
|
|
|
76a39a |
fp = fdopen(fd, "r");
|
|
|
76a39a |
- if (fp == NULL)
|
|
|
76a39a |
+ if (fp == NULL) {
|
|
|
76a39a |
+ close(fd);
|
|
|
76a39a |
return;
|
|
|
76a39a |
- if (fscanf(fp, "%d", &pid) != 1)
|
|
|
76a39a |
+ }
|
|
|
76a39a |
+ if (fscanf(fp, "%d", &pid) != 1) {
|
|
|
76a39a |
+ fclose(fp);
|
|
|
76a39a |
return;
|
|
|
76a39a |
+ } else {
|
|
|
76a39a |
+ fclose(fp);
|
|
|
76a39a |
+ }
|
|
|
76a39a |
|
|
|
76a39a |
kill_errno = 0;
|
|
|
76a39a |
|
|
|
76a39a |
@@ -640,6 +650,8 @@ list_jobs(void)
|
|
|
76a39a |
else
|
|
|
76a39a |
printf("%ld\t%s %c\n", jobno, timestr, queue);
|
|
|
76a39a |
}
|
|
|
76a39a |
+ closedir(spool);
|
|
|
76a39a |
+
|
|
|
76a39a |
PRIV_END
|
|
|
76a39a |
}
|
|
|
76a39a |
|
|
|
76a39a |
@@ -722,6 +734,8 @@ process_jobs(int argc, char **argv, int what)
|
|
|
76a39a |
putchar(ch);
|
|
|
76a39a |
}
|
|
|
76a39a |
done = 1;
|
|
|
76a39a |
+ fclose(fp);
|
|
|
76a39a |
+ fp = NULL;
|
|
|
76a39a |
}
|
|
|
76a39a |
else {
|
|
|
76a39a |
perr("Cannot open %.500s", dirent->d_name);
|
|
|
76a39a |
diff --git a/daemon.c b/daemon.c
|
|
|
76a39a |
index 4003b56..bc8191e 100644
|
|
|
76a39a |
--- a/daemon.c
|
|
|
76a39a |
+++ b/daemon.c
|
|
|
76a39a |
@@ -122,18 +122,23 @@ daemon_setup()
|
|
|
76a39a |
/* Set up standard daemon environment */
|
|
|
76a39a |
pid_t pid;
|
|
|
76a39a |
mode_t old_umask;
|
|
|
76a39a |
- int fd;
|
|
|
76a39a |
+ int fd, devnull;
|
|
|
76a39a |
FILE *fp;
|
|
|
76a39a |
|
|
|
76a39a |
if (!daemon_debug) {
|
|
|
76a39a |
- close(0);
|
|
|
76a39a |
- close(1);
|
|
|
76a39a |
- close(2);
|
|
|
76a39a |
- if ((open("/dev/null", O_RDWR) != 0) ||
|
|
|
76a39a |
- (open("/dev/null", O_RDWR) != 1) ||
|
|
|
76a39a |
- (open("/dev/null", O_RDWR) != 2)) {
|
|
|
76a39a |
+ devnull = open("/dev/null", O_RDWR);
|
|
|
76a39a |
+ if (devnull == -1) {
|
|
|
76a39a |
perr("Error redirecting I/O");
|
|
|
76a39a |
}
|
|
|
76a39a |
+
|
|
|
76a39a |
+ if ((dup2(devnull, 0) == -1) ||
|
|
|
76a39a |
+ (dup2(devnull, 1) == -1) ||
|
|
|
76a39a |
+ (dup2(devnull, 2) == -1)) {
|
|
|
76a39a |
+ close(devnull);
|
|
|
76a39a |
+ perr("Error redirecting I/O");
|
|
|
76a39a |
+ } else {
|
|
|
76a39a |
+ close(devnull);
|
|
|
76a39a |
+ }
|
|
|
76a39a |
}
|
|
|
76a39a |
|
|
|
76a39a |
if (daemon_foreground)
|
|
|
76a39a |
@@ -208,6 +213,8 @@ daemon_setup()
|
|
|
76a39a |
fcntl(fd, F_SETFD, FD_CLOEXEC);
|
|
|
76a39a |
PRIV_END
|
|
|
76a39a |
|
|
|
76a39a |
+ /* See the above comment. */
|
|
|
76a39a |
+ /* coverity[leaked_storage: FALSE] */
|
|
|
76a39a |
return;
|
|
|
76a39a |
}
|
|
|
76a39a |
|
|
|
76a39a |
--
|
|
|
76a39a |
2.31.1
|
|
|
76a39a |
|