Subject: fixing PR bin/27145 -- yptest(8) core dumps
To: None <tech-userlevel@NetBSD.org>
From: Peter Postma <peter@pointless.nl>
List: tech-userlevel
Date: 10/22/2004 15:51:05
Hello,

The following patch fixes core dump from yptest(8) if yp(8) is not
configured. Test 4 dumps core in printf if yp_master fails because Key2 is
invalid (NULL).
The patch also adds error messages for when the other tests fail.

Is this ok to commit?


Index: yptest.c
===================================================================
RCS file: /cvsroot/src/usr.sbin/ypserv/yptest/yptest.c,v
retrieving revision 1.6
diff -u -r1.6 yptest.c
--- yptest.c	6 Jul 2002 00:47:55 -0000	1.6
+++ yptest.c	22 Oct 2004 13:27:50 -0000
@@ -72,11 +72,18 @@
 	printf("Test 1: yp_match\n");
 	KeyLen = strlen(Key);
 	Status = yp_match(Domain, Map, Key, KeyLen, &Value, &ValLen);
-	printf("%*.*s\n", ValLen, ValLen, Value);
+	if (Status == 0)
+		printf("%*.*s\n", ValLen, ValLen, Value);
+	else
+		fprintf(stderr, "yp error: %s\n", yperr_string(Status));
 
 	printf("\nTest 2: yp_first\n");
 	Status = yp_first(Domain, Map, &Key2, &KeyLen, &Value, &ValLen);
-	printf("%*.*s %*.*s\n", KeyLen, KeyLen, Key2, ValLen, ValLen, Value);
+	if (Status == 0)
+		printf("%*.*s %*.*s\n", KeyLen, KeyLen, Key2, ValLen, ValLen,
+		    Value);
+	else
+		fprintf(stderr, "yp error: %s\n", yperr_string(Status));
 
 	printf("\nTest 3: yp_next\n");
 	while (Status == 0) {
@@ -85,15 +92,23 @@
 		if (Status == 0)
 			printf("%*.*s %*.*s\n", KeyLen, KeyLen, Key2,
 			    ValLen, ValLen, Value);
+		else
+			fprintf(stderr, "yp error: %s\n", yperr_string(Status));
 	}
 
 	printf("\nTest 4: yp_master\n");
 	Status = yp_master(Domain, Map, &Key2);
-	printf("%s\n", Key2);
+	if (Status == 0)
+		printf("%s\n", Key2);
+	else
+		fprintf(stderr, "yp error: %s\n", yperr_string(Status));
 
 	printf("\nTest 5: yp_order\n");
 	Status = yp_order(Domain, Map, &Order);
-	printf("%d\n", Order);
+	if (Status == 0)
+		printf("%d\n", Order);
+	else
+		fprintf(stderr, "yp error: %s\n", yperr_string(Status));
 
 	printf("\nTest 6: yp_maplist\n");
 	ypml = NULL;
@@ -104,11 +119,18 @@
 			printf("%s\n", ypml->ypml_name);
 			y = ypml->ypml_next;
 		}
+		break;
+	default:
+		fprintf(stderr, "yp error: %s\n", yperr_string(Status));
+		break;
 	}
 
 	printf("\nTest 7: yp_all\n");
 	Callback.foreach = yptest_foreach;
 	Status = yp_all(Domain, Map, &Callback);
+	if (Status != 0)
+		fprintf(stderr, "yp error: %s\n", yperr_string(Status));
+
 	exit(0);
 }
 

-- 
Peter Postma