[comp.sources.bugs] Bug in Sun RPC 3.9

mark@comp.vuw.ac.nz (Mark Davies) (08/17/88)

Problem:

The Sun RPC 3.9 release, posted to the net several months ago has a bug in
the routines that look up the /etc/rpc file.  The aliases are not extracted
and under certain conditions the routine getrpcbynumber will fail to find
an entry.

Repeat By:

Edit your /etc/rpc file so that tabs are used to separate the prog-name
from the prog-number but spaces are used to separate the prog-number from
the aliases, and run rpcinfo -p.  Note that rpcinfo nolonger displays the
program names.

or compile and run the following program

----cut here-----
#include <stdio.h>
#include <rpc/netdb.h>

main ()
{
	register struct rpcent *p;
	char **q;

	setrpcent (0);
	while (p = getrpcent()) {
		printf ("%d %s\n", p->r_number, p->r_name);
		for (q=p->r_aliases; *q; q++)
			printf ("   - [%s]\n", *q);
	}
	endrpcent();
}
----cut here-----

Fix:

Apply the following context diff

*** getrpcent.c~	Mon Apr 18 19:44:05 1988
--- getrpcent.c	Wed Aug 17 22:11:23 1988
***************
*** 190,202 ****
  			return (getrpcent());
  	}
  	*cp = '\0';
! 	cp = index(p, ' ');
! 	if (cp == NULL)
!     {
! 		cp = index(p, '\t');
! 		if (cp == NULL)
! 			return (getrpcent());
! 	}
  	*cp++ = '\0';
  	/* THIS STUFF IS INTERNET SPECIFIC */
  	d->rpc.r_name = d->line;
--- 190,200 ----
  			return (getrpcent());
  	}
  	*cp = '\0';
! 	cp = p;
! #define SKIP_OVER_FIELD(cp) for (; *cp && *cp != ' ' && *cp != '\t'; cp++)
! 	SKIP_OVER_FIELD(cp);
! 	if (!(*cp))
! 		return (getrpcent());
  	*cp++ = '\0';
  	/* THIS STUFF IS INTERNET SPECIFIC */
  	d->rpc.r_name = d->line;
***************
*** 203,218 ****
  	while (*cp == ' ' || *cp == '\t')
  		cp++;
  	d->rpc.r_number = atoi(cp);
  	q = d->rpc.r_aliases = d->rpc_aliases;
- 	cp = index(p, ' ');
- 	if (cp != NULL)
- 		*cp++ = '\0';
- 	else
-     {
- 		cp = index(p, '\t');
- 		if (cp != NULL)
- 			*cp++ = '\0';
- 	}
  	while (cp && *cp) {
  		if (*cp == ' ' || *cp == '\t') {
  			cp++;
--- 201,211 ----
  	while (*cp == ' ' || *cp == '\t')
  		cp++;
  	d->rpc.r_number = atoi(cp);
+ 	/* skip program number */
+ 	SKIP_OVER_FIELD (cp);
+ 
+ 	/* handle aliases if present */
  	q = d->rpc.r_aliases = d->rpc_aliases;
  	while (cp && *cp) {
  		if (*cp == ' ' || *cp == '\t') {
  			cp++;
***************
*** 220,234 ****
  		}
  		if (q < &(d->rpc_aliases[MAXALIASES - 1]))
  			*q++ = cp;
! 		cp = index(p, ' ');
! 		if (cp != NULL)
  			*cp++ = '\0';
- 		else
- 	    {
- 			cp = index(p, '\t');
- 			if (cp != NULL)
- 				*cp++ = '\0';
- 		}
  	}
  	*q = NULL;
  	return (&d->rpc);
--- 213,221 ----
  		}
  		if (q < &(d->rpc_aliases[MAXALIASES - 1]))
  			*q++ = cp;
! 		SKIP_OVER_FIELD(cp);
! 		if (*cp)
  			*cp++ = '\0';
  	}
  	*q = NULL;
  	return (&d->rpc);
-- 
Domainised:  mark@comp.vuw.ac.nz	Bang form: ...!uunet!vuwcomp!mark