Subject: lib/23294: getrpcbyname() does not find entries when using an alias
To: None <gnats-bugs@gnats.netbsd.org>
From: Brian Ginsbach <ginsbach@cray.com>
List: netbsd-bugs
Date: 10/28/2003 09:14:46
>Number: 23294
>Category: lib
>Synopsis: getrpcbyname() does not find entries when using an alias
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: lib-bug-people
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Tue Oct 28 17:55:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator: Brian Ginsbach
>Release: NetBSD 1.6.1, current
>Organization:
Cray Inc.
>Environment:
n.a.
Architecture: i386
Machine: i386
>Description:
The getrpcbyname(3) function fails to find a /etc/rpc entry
when given a server alias rather than a server name. It
appears that this was broken at rev 1.6. The break statement
in the alias search loop does not exit the enclosing while loop.
>How-To-Repeat:
The following test illustrates the problem. Source for
getrpcbyname.c test program included below.
nbtest> grep keyserv /etc/rpc
keyserv 100029 keyserver
nbtest> ./getrpcbyname keyserv
Name : keyserv
Number : 100029
Aliases: keyserver
nbtest> ./getrpcbyname keyserver
getrpcbyname: getrpcbyname(): keyserver: name not found
This should return the same data as getrpcbyname keyserv.
/*
* Copyright (c) 2003 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code was contributed to The NetBSD Foundation by Brian Ginsbach.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of The NetBSD Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <rpc/rpc.h>
int
main(int argc, char **argv)
{
struct rpcent *r;
int i, errflag = 0, estatus = 0;
if (argc < 2) {
fprintf(stderr, "Usage: %s rpc-name [rpc-name ...]\n", getprogname());
exit(-1);
}
for (argc--, argv++; argc > 0; argc--, argv++) {
if ((r = getrpcbyname(*argv)) == 0) {
warnx("getrpcbyname(): %s: name not found", *argv);
estatus++;
}
else {
printf("Name : %s\n", r->r_name);
printf("Number : %d\n", r->r_number);
printf("Aliases: ");
for (i = 0; r->r_aliases[i]; i++) {
printf("%s%s", (i > 0) ? ", " : "", r->r_aliases[i]);
}
printf("\n\n");
}
}
return (estatus);
}
>Fix:
This logic is similar to the logic in getprotobyname(3)
(which works correctly) and FreeBSD's getrpcbyname(3).
--- getrpcent.c 2001/01/04 14:57:17 1.18
+++ getrpcent.c 2003/10/27 22:07:57
@@ -123,12 +123,13 @@
setrpcent(0);
while ((rpc = getrpcent()) != NULL) {
if (strcmp(rpc->r_name, name) == 0)
- break;
+ goto found;
for (rp = rpc->r_aliases; *rp != NULL; rp++) {
if (strcmp(*rp, name) == 0)
- break;
+ goto found;
}
}
+found:
endrpcent();
return (rpc);
}
>Release-Note:
>Audit-Trail:
>Unformatted: