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);
 
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to