Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 16 Apr 2018 16:32:01 +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-11@freebsd.org
Subject:   svn commit: r332608 - in stable/11: etc/mtree libexec/tftpd libexec/tftpd/tests
Message-ID:  <201804161632.w3GGW144002866@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: asomers
Date: Mon Apr 16 16:32:00 2018
New Revision: 332608
URL: https://svnweb.freebsd.org/changeset/base/332608

Log:
  MFC r330696, r330709, r330742, r331358
  
  r330696:
  Add some functional tests for tftpd(8)
  
  tftpd(8) is difficult to test in isolation due to its relationship with
  inetd.  Create a test program that mimics the behavior of tftp(1) and
  inetd(8) and verifies tftpd's response in several different scenarios.
  
  These test cases cover all of the basic TFTP protocol, but not the optional
  parts.
  
  PR:		157700
  PR:		225996
  PR:		226004
  PR:		226005
  Differential Revision:	https://reviews.freebsd.org/D14310
  
  r330709:
  Commit missing file from r330696
  
  X-MFC-With:	330696
  
  r330742:
  tftpd: fix the build of tests on i386 after 330696
  
  It's those darn printf format specifiers again
  
  Reported by:	cy, kibab
  X-MFC-With:	330696
  
  r331358:
  tftpd: misc Coverity cleanup in the tests
  
  A bunch of unchecked return values from open(2) and read(2)
  
  Reported by:	Coverity
  CID:		1386900, 1386911, 1386926, 1386928, 1386932, 1386942
  CID:		1386961, 1386979
  X-MFC-With:	330696

Added:
  stable/11/libexec/tftpd/tests/
     - copied from r330696, head/libexec/tftpd/tests/
Modified:
  stable/11/etc/mtree/BSD.tests.dist
  stable/11/libexec/tftpd/Makefile
  stable/11/libexec/tftpd/tests/functional.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/etc/mtree/BSD.tests.dist
==============================================================================
--- stable/11/etc/mtree/BSD.tests.dist	Mon Apr 16 16:29:48 2018	(r332607)
+++ stable/11/etc/mtree/BSD.tests.dist	Mon Apr 16 16:32:00 2018	(r332608)
@@ -376,6 +376,8 @@
         ..
         rtld-elf
         ..
+        tftpd
+        ..
     ..
     sbin
         dhclient

Modified: stable/11/libexec/tftpd/Makefile
==============================================================================
--- stable/11/libexec/tftpd/Makefile	Mon Apr 16 16:29:48 2018	(r332607)
+++ stable/11/libexec/tftpd/Makefile	Mon Apr 16 16:32:00 2018	(r332608)
@@ -14,4 +14,7 @@ CFLAGS+=	-DLIBWRAP
 LIBADD=	wrap
 .endif
 
+HAS_TESTS=
+SUBDIR.${MK_TESTS}+= tests
+
 .include <bsd.prog.mk>

Modified: stable/11/libexec/tftpd/tests/functional.c
==============================================================================
--- head/libexec/tftpd/tests/functional.c	Fri Mar  9 15:30:20 2018	(r330696)
+++ stable/11/libexec/tftpd/tests/functional.c	Mon Apr 16 16:32:00 2018	(r332608)
@@ -224,19 +224,17 @@ do { \
 static void
 cleanup(void)
 {
-	int fd = -1;
-	char buffer[80] = {0};
+	FILE *f;
 	pid_t pid;
 
-	fd = open(pidfile, O_RDONLY);
-	if (fd < 0)
+	f = fopen(pidfile, "r");
+	if (f == NULL)
 		return;
-	if (read(fd, buffer, sizeof(buffer)) > 0) {
-		sscanf(buffer, "%d", &pid);
+	if (fscanf(f, "%d", &pid) == 1) {
 		kill(pid, SIGTERM);
 		waitpid(pid, NULL, 0);
 	}
-	close(fd);
+	fclose(f);
 	unlink(pidfile);
 }
 
@@ -248,10 +246,10 @@ require_bufeq(const char *expected, ssize_t expected_l
 	ssize_t i;
 
 	ATF_REQUIRE_EQ_MSG(expected_len, len,
-	    "Expected %ld bytes but got %ld", expected_len, len);
+	    "Expected %zd bytes but got %zd", expected_len, len);
 	for (i = 0; i < len; i++) {
 		ATF_REQUIRE_EQ_MSG(actual[i], expected[i],
-		    "Expected %#hhx at position %ld; got %hhx instead",
+		    "Expected %#hhx at position %zd; got %hhx instead",
 		    expected[i], i, actual[i]);
 	}
 }
@@ -696,6 +694,7 @@ TFTPD_TC_DEFINE(w_flag,, w_flag = 1;)
 
 	atf_tc_expect_fail("PR 157700 tftpd expects more data after EOF");
 	fd = open("small.txt", O_RDONLY);
+	ATF_REQUIRE(fd >= 0);
 	r = read(fd, buffer, sizeof(buffer));
 	close(fd);
 	require_bufeq(contents, contents_len, buffer, r);
@@ -733,6 +732,7 @@ TFTPD_TC_DEFINE(wrq_dropped_ack,)
 
 	atf_tc_expect_fail("PR 157700 tftpd expects more data after EOF");
 	fd = open("medium.txt", O_RDONLY);
+	ATF_REQUIRE(fd >= 0);
 	r = read(fd, buffer, sizeof(buffer));
 	close(fd);
 	require_bufeq((const char*)contents, 768, buffer, r);
@@ -766,6 +766,7 @@ TFTPD_TC_DEFINE(wrq_dropped_data,)
 
 	atf_tc_expect_fail("PR 157700 tftpd expects more data after EOF");
 	fd = open("small.txt", O_RDONLY);
+	ATF_REQUIRE(fd >= 0);
 	r = read(fd, buffer, sizeof(buffer));
 	close(fd);
 	require_bufeq(contents, contents_len, buffer, r);
@@ -800,6 +801,7 @@ TFTPD_TC_DEFINE(wrq_duped_data,)
 
 	atf_tc_expect_fail("PR 157700 tftpd expects more data after EOF");
 	fd = open("medium.txt", O_RDONLY);
+	ATF_REQUIRE(fd >= 0);
 	r = read(fd, buffer, sizeof(buffer));
 	close(fd);
 	require_bufeq((const char*)contents, 768, buffer, r);
@@ -867,6 +869,7 @@ TFTPD_TC_DEFINE(wrq_medium,)
 
 	atf_tc_expect_fail("PR 157700 tftpd expects more data after EOF");
 	fd = open("medium.txt", O_RDONLY);
+	ATF_REQUIRE(fd >= 0);
 	r = read(fd, buffer, sizeof(buffer));
 	close(fd);
 	require_bufeq((const char*)contents, 768, buffer, r);
@@ -900,6 +903,7 @@ TFTPD_TC_DEFINE(wrq_netascii,)
 
 	atf_tc_expect_fail("PR 157700 tftpd expects more data after EOF");
 	fd = open("unix.txt", O_RDONLY);
+	ATF_REQUIRE(fd >= 0);
 	r = read(fd, buffer, sizeof(buffer));
 	close(fd);
 	require_bufeq(expected, sizeof(expected), buffer, r);
@@ -940,6 +944,7 @@ TFTPD_TC_DEFINE(wrq_small,)
 
 	atf_tc_expect_fail("PR 157700 tftpd expects more data after EOF");
 	fd = open("small.txt", O_RDONLY);
+	ATF_REQUIRE(fd >= 0);
 	r = read(fd, buffer, sizeof(buffer));
 	close(fd);
 	require_bufeq(contents, contents_len, buffer, r);



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