aboutgitcodebugslistschat
diff options
context:
space:
mode:
authorStefano Brivio <sbrivio@redhat.com>2022-04-05 08:15:29 +0200
committerStefano Brivio <sbrivio@redhat.com>2022-04-07 11:44:35 +0200
commitbb76470090dc21540e70c3417fe0227c5a62cce2 (patch)
tree05a8b23553d54c547fd2bd689ed9946fda89ff6e
parent0786b2e60a71c94b4243224d01a810a4a52b8b72 (diff)
downloadpasst-bb76470090dc21540e70c3417fe0227c5a62cce2.tar
passt-bb76470090dc21540e70c3417fe0227c5a62cce2.tar.gz
passt-bb76470090dc21540e70c3417fe0227c5a62cce2.tar.bz2
passt-bb76470090dc21540e70c3417fe0227c5a62cce2.tar.lz
passt-bb76470090dc21540e70c3417fe0227c5a62cce2.tar.xz
passt-bb76470090dc21540e70c3417fe0227c5a62cce2.tar.zst
passt-bb76470090dc21540e70c3417fe0227c5a62cce2.zip
passt: Improper use of negative value (CWE-394)
Reported by Coverity. Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
-rw-r--r--passt.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/passt.c b/passt.c
index 06c3d73..8781a7f 100644
--- a/passt.c
+++ b/passt.c
@@ -421,13 +421,22 @@ int main(int argc, char **argv)
pcap_init(&c);
- if (!c.foreground)
+ if (!c.foreground) {
/* NOLINTNEXTLINE(android-cloexec-open): see __daemon() */
- devnull_fd = open("/dev/null", O_RDWR);
+ if ((devnull_fd = open("/dev/null", O_RDWR)) < 0) {
+ perror("/dev/null open");
+ exit(EXIT_FAILURE);
+ }
+ }
- if (*c.pid_file)
- pidfile_fd = open(c.pid_file, O_CREAT | O_WRONLY | O_CLOEXEC,
- S_IRUSR | S_IWUSR);
+ if (*c.pid_file) {
+ if ((pidfile_fd = open(c.pid_file,
+ O_CREAT | O_WRONLY | O_CLOEXEC,
+ S_IRUSR | S_IWUSR)) < 0) {
+ perror("PID file open");
+ exit(EXIT_FAILURE);
+ }
+ }
if (sandbox(&c)) {
err("Failed to sandbox process, exiting\n");