Blame SOURCES/0001-Coverity-scan-fixes.patch

5f4533
From f8e7499e9f69465668fc6e5e7bcfb9ce09e8a457 Mon Sep 17 00:00:00 2001
5f4533
From: Chris Leech <cleech@redhat.com>
5f4533
Date: Wed, 5 Jun 2019 09:08:39 -0700
5f4533
Subject: [PATCH] Coverity scan fixes
5f4533
5f4533
---
5f4533
 iscsiuio/src/unix/libs/qedi.c |  2 +-
5f4533
 iscsiuio/src/unix/main.c      | 12 ++++++++++--
5f4533
 libopeniscsiusr/idbm.c        | 11 +++++------
5f4533
 usr/idbm.c                    | 10 ++++------
5f4533
 usr/iscsid.c                  |  2 +-
5f4533
 5 files changed, 21 insertions(+), 16 deletions(-)
5f4533
5f4533
diff --git a/iscsiuio/src/unix/libs/qedi.c b/iscsiuio/src/unix/libs/qedi.c
5f4533
index b7595d5..47300b0 100644
5f4533
--- a/iscsiuio/src/unix/libs/qedi.c
5f4533
+++ b/iscsiuio/src/unix/libs/qedi.c
5f4533
@@ -1023,7 +1023,7 @@ static int qedi_read(nic_t *nic, packet_t *pkt)
5f4533
 
5f4533
 	LOG_DEBUG(PFX "%s:hw_prod %d bd_prod %d, rx_pkt_idx %d, rxlen %d",
5f4533
 		  nic->log_name, hw_prod, bd_prod, rx_bd->rx_pkt_index, len);
5f4533
-	LOG_DEBUG(PFX "%s: sw_con %d bd_cons %d num BD %d",
5f4533
+	LOG_DEBUG(PFX "%s: sw_con %d bd_cons %d num BD %lu",
5f4533
 		  nic->log_name, sw_cons, bd_cons, QEDI_NUM_RX_BD);
5f4533
 
5f4533
 	if (bd_cons != bd_prod) {
5f4533
diff --git a/iscsiuio/src/unix/main.c b/iscsiuio/src/unix/main.c
5f4533
index 5168e4e..ed41931 100644
5f4533
--- a/iscsiuio/src/unix/main.c
5f4533
+++ b/iscsiuio/src/unix/main.c
5f4533
@@ -340,7 +340,10 @@ int main(int argc, char *argv[])
5f4533
 
5f4533
 			/* parent: wait for child msg then exit */
5f4533
 			close(pipefds[1]);
5f4533
-			read(pipefds[0], msgbuf, sizeof(msgbuf));
5f4533
+			if (read(pipefds[0], msgbuf, sizeof(msgbuf)) < 0) {
5f4533
+				fprintf(stderr, "ERR: Waiting for child process failed\n");
5f4533
+				exit(1);
5f4533
+			}
5f4533
 			exit(0);
5f4533
 		}
5f4533
 
5f4533
@@ -386,6 +389,9 @@ int main(int argc, char *argv[])
5f4533
 	sigaddset(&set, SIGTERM);
5f4533
 	sigaddset(&set, SIGUSR1);
5f4533
 	rc = pthread_sigmask(SIG_SETMASK, &set, NULL);
5f4533
+	if (rc != 0) {
5f4533
+		LOG_ERR("Failed to set thread signal mask");
5f4533
+	}
5f4533
 
5f4533
 	/*  Spin off the signal handling thread */
5f4533
 	pthread_attr_init(&attr);
5f4533
@@ -415,7 +421,9 @@ int main(int argc, char *argv[])
5f4533
 	if (!foreground) {
5f4533
 		/* signal parent they can go away now */
5f4533
 		close(pipefds[0]);
5f4533
-		write(pipefds[1], "ok\n", 3);
5f4533
+		if (write(pipefds[1], "ok\n", 3) < 0) {
5f4533
+			LOG_ERR("Failed to signal parent process of completed initialization");
5f4533
+		}
5f4533
 		close(pipefds[1]);
5f4533
 	}
5f4533
 
5f4533
diff --git a/libopeniscsiusr/idbm.c b/libopeniscsiusr/idbm.c
5f4533
index d020e6c..342aab5 100644
5f4533
--- a/libopeniscsiusr/idbm.c
5f4533
+++ b/libopeniscsiusr/idbm.c
5f4533
@@ -287,12 +287,11 @@ int _idbm_lock(struct iscsi_context *ctx)
5f4533
 		return 0;
5f4533
 	}
5f4533
 
5f4533
-	if (access(LOCK_DIR, F_OK) != 0) {
5f4533
-		if (mkdir(LOCK_DIR, 0660) != 0) {
5f4533
-			_error(ctx, "Could not open %s: %d %s", LOCK_DIR, errno,
5f4533
-				_strerror(errno, strerr_buff));
5f4533
-			return LIBISCSI_ERR_IDBM;
5f4533
-		}
5f4533
+	if (((mkdir(LOCK_DIR, 0660) != 0) && (errno != EEXIST)) ||
5f4533
+	    (access(LOCK_DIR, F_OK) != 0)) {
5f4533
+		_error(ctx, "Could not open %s: %d %s", LOCK_DIR, errno,
5f4533
+			_strerror(errno, strerr_buff));
5f4533
+		return LIBISCSI_ERR_IDBM;
5f4533
 	}
5f4533
 
5f4533
 	fd = open(LOCK_FILE, O_RDWR | O_CREAT, 0666);
5f4533
diff --git a/usr/idbm.c b/usr/idbm.c
5f4533
index 89a6c27..a3343fe 100644
5f4533
--- a/usr/idbm.c
5f4533
+++ b/usr/idbm.c
5f4533
@@ -1332,12 +1332,10 @@ int idbm_lock(void)
5f4533
 		return 0;
5f4533
 	}
5f4533
 
5f4533
-	if (access(LOCK_DIR, F_OK) != 0) {
5f4533
-		if (mkdir(LOCK_DIR, 0660) != 0) {
5f4533
-			log_error("Could not open %s: %s", LOCK_DIR,
5f4533
-				  strerror(errno));
5f4533
-			return ISCSI_ERR_IDBM;
5f4533
-		}
5f4533
+	if (((mkdir(LOCK_DIR, 0660) != 0) && (errno != EEXIST)) ||
5f4533
+	    (access(LOCK_DIR, F_OK) != 0)) {
5f4533
+		log_error("Could not open %s: %s", LOCK_DIR, strerror(errno));
5f4533
+		return ISCSI_ERR_IDBM;
5f4533
 	}
5f4533
 
5f4533
 	fd = open(LOCK_FILE, O_RDWR | O_CREAT, 0666);
5f4533
diff --git a/usr/iscsid.c b/usr/iscsid.c
5f4533
index 37c13b3..1891784 100644
5f4533
--- a/usr/iscsid.c
5f4533
+++ b/usr/iscsid.c
5f4533
@@ -489,8 +489,8 @@ int main(int argc, char *argv[])
5f4533
 				log_close(log_pid);
5f4533
 				exit(ISCSI_ERR);
5f4533
 			}
5f4533
+			close(fd);
5f4533
 		}
5f4533
-		close(fd);
5f4533
 
5f4533
 		if ((control_fd = ipc->ctldev_open()) < 0) {
5f4533
 			log_close(log_pid);
5f4533
-- 
5f4533
2.21.0
5f4533