Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 8 Apr 2016 20:43:50 +0000 (UTC)
From:      Alan Somers <asomers@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject:   svn commit: r297723 - stable/10/sbin/devd/tests
Message-ID:  <201604082043.u38Khori062603@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: asomers
Date: Fri Apr  8 20:43:50 2016
New Revision: 297723
URL: https://svnweb.freebsd.org/changeset/base/297723

Log:
  MFC 270231
  
  Misc fixes suggested by Coverity.
  
  sbin/devd/tests/client_test.c
  	* In the event that popen fails, don't dereference its return value.
  	* Fix array overwrite in the stream and seqpacket tests.
  	* Close sockets at the end of successful ATF tests.

Modified:
  stable/10/sbin/devd/tests/client_test.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sbin/devd/tests/client_test.c
==============================================================================
--- stable/10/sbin/devd/tests/client_test.c	Fri Apr  8 18:15:31 2016	(r297722)
+++ stable/10/sbin/devd/tests/client_test.c	Fri Apr  8 20:43:50 2016	(r297723)
@@ -58,6 +58,7 @@ create_two_events(void)
 
 	snprintf(destroy_cmd, nitems(destroy_cmd), "mdconfig -d -u %s", mdname);
 	destroy_stdout = popen(destroy_cmd, "r");
+	ATF_REQUIRE(destroy_stdout != NULL);
 	/* We expect no output */
 	ATF_REQUIRE_EQ(0, pclose(destroy_stdout));
 }
@@ -105,7 +106,8 @@ ATF_TC_BODY(seqpacket, tc)
 		ssize_t len;
 		char event[1024];
 
-		len = recv(s, event, sizeof(event), MSG_WAITALL);
+		/* Read 1 less than sizeof(event) to allow space for NULL */
+		len = recv(s, event, sizeof(event) - 1, MSG_WAITALL);
 		ATF_REQUIRE(len != -1);
 		/* NULL terminate the result */
 		event[len] = '\0';
@@ -118,6 +120,8 @@ ATF_TC_BODY(seqpacket, tc)
 		if (cmp == 0)
 			got_destroy_event = true;
 	}
+
+	close(s);
 }
 
 /*
@@ -160,7 +164,8 @@ ATF_TC_BODY(stream, tc)
 		ssize_t newlen;
 		char *create_pos, *destroy_pos;
 
-		newlen = read(s, &event[len], sizeof(event) - len);
+		/* Read 1 less than sizeof(event) to allow space for NULL */
+		newlen = read(s, &event[len], sizeof(event) - len - 1);
 		ATF_REQUIRE(newlen != -1);
 		len += newlen;
 		/* NULL terminate the result */
@@ -174,8 +179,9 @@ ATF_TC_BODY(stream, tc)
 		destroy_pos = strstr(event, destroy_pat);
 		if (destroy_pos != NULL)
 			got_destroy_event = true;
-
 	}
+
+	close(s);
 }
 
 /*



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