Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 13 Feb 2018 19:17:33 +0000 (UTC)
From:      Alan Somers <asomers@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r329236 - head/contrib/netbsd-tests/kernel
Message-ID:  <201802131917.w1DJHXfY047411@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: asomers
Date: Tue Feb 13 19:17:33 2018
New Revision: 329236
URL: https://svnweb.freebsd.org/changeset/base/329236

Log:
  Fix Coverity CIDs in the sys/kern/sysv_test tests
  
  CID 979810: strcpy => strlcpy
  CID 1193367: don't leak a file descriptor
  CID 1299856: Check the return value of read(2)
  
  Reported by:	Coverity
  Coverity CID:	978910 1193367 1299856
  MFC after:	3 weeks
  X-MFC-With:	328896
  Sponsored by:	Spectra Logic Corp

Modified:
  head/contrib/netbsd-tests/kernel/t_sysv.c

Modified: head/contrib/netbsd-tests/kernel/t_sysv.c
==============================================================================
--- head/contrib/netbsd-tests/kernel/t_sysv.c	Tue Feb 13 17:58:02 2018	(r329235)
+++ head/contrib/netbsd-tests/kernel/t_sysv.c	Tue Feb 13 19:17:33 2018	(r329236)
@@ -129,7 +129,8 @@ read_int(const char *path)
 		return -1;
 	else {
 		int value;
-		read(input, &value, sizeof(value));
+		ATF_REQUIRE_EQ(read(input, &value, sizeof(value)), sizeof(value));
+		close(input);
 		return value;
 	}
 }
@@ -284,7 +285,7 @@ ATF_TC_BODY(msg, tc)
 		 * Send the first message to the receiver and wait for the ACK.
 		 */
 		m.mtype = MTYPE_1;
-		strcpy(m.mtext, m1_str);
+		strlcpy(m.mtext, m1_str, sizeof(m.mtext));
 		ATF_REQUIRE_MSG(msgsnd(sender_msqid, &m, MESSAGE_TEXT_LEN,
 		    0) != -1, "sender: msgsnd 1: %d", errno);
 
@@ -298,7 +299,7 @@ ATF_TC_BODY(msg, tc)
 		 * Send the second message to the receiver and wait for the ACK.
 		 */
 		m.mtype = MTYPE_2;
-		strcpy(m.mtext, m2_str);
+		strlcpy(m.mtext, m2_str, sizeof(m.mtext));
 		ATF_REQUIRE_MSG(msgsnd(sender_msqid, &m, MESSAGE_TEXT_LEN, 0) != -1,
 		    "sender: msgsnd 2: %d", errno);
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201802131917.w1DJHXfY047411>