Subject: Re: fixing PR bin/27145 -- yptest(8) core dumps
To: None <tech-userlevel@netbsd.org>
From: Christos Zoulas <christos@zoulas.com>
List: tech-userlevel
Date: 10/22/2004 17:26:37
In article <20041022135105.GA20151@gateway.pointless.nl>,
Peter Postma <peter@pointless.nl> wrote:
>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?

Yes, the only concern is that the program printf's to stdout and err
at the same time, so that the output might get mixed when sent to a
file. Maybe include the function name that produced the error in
the error string and merge the printfs:

	KeyLen = strlen(Key);
	Status = yp_match(Domain, Map, Key, KeyLen, &Value, &ValLen);
	if (Status == 0)
		printf("yp_match test: %*.*s\n", ValLen, ValLen, Value);
	else
		printf("yp_match error: %s\n", yperr_string(Status));

Since it is a test it is probably ok to produce diagnostic output to
stdout, and keep going when it fails.

christos

>
>
>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");
> 
> 	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