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

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