- OpenBSD's strncpy fixes to ensure NULL termination

- missed endrpcent() in some cases.

Obtained from: a diff of FreeBSD vs. OpenBSD/NetBSD rpc code.
This commit is contained in:
Peter Wemm 1996-12-30 14:42:31 +00:00
parent 5df070f36d
commit e7485a4786

View File

@ -30,7 +30,7 @@
#if defined(LIBC_SCCS) && !defined(lint)
/*static char *sccsid = "from: @(#)getrpcent.c 1.14 91/03/11 Copyr 1984 Sun Micro";*/
static char *rcsid = "$Id: getrpcent.c,v 1.4 1996/06/10 20:13:04 jraynard Exp $";
static char *rcsid = "$Id: getrpcent.c,v 1.5 1996/06/11 17:22:48 jraynard Exp $";
#endif
/*
@ -136,20 +136,21 @@ struct rpcent *
getrpcbyname(name)
char *name;
{
struct rpcent *rpc;
struct rpcent *rpc = NULL;
char **rp;
setrpcent(0);
while ((rpc = getrpcent())) {
if (strcmp(rpc->r_name, name) == 0)
return (rpc);
goto done;
for (rp = rpc->r_aliases; *rp != NULL; rp++) {
if (strcmp(*rp, name) == 0)
return (rpc);
goto done;
}
}
done:
endrpcent();
return (NULL);
return (rpc);
}
void
@ -245,7 +246,8 @@ no_yp:
#endif /* YP */
if (d->rpcf == NULL && (d->rpcf = fopen(RPCDB, "r")) == NULL)
return (NULL);
if (fgets(d->line, BUFSIZ, d->rpcf) == NULL)
/* -1 so there is room to append a \n below */
if (fgets(d->line, BUFSIZ - 1, d->rpcf) == NULL)
return (NULL);
return (interpret(d->line, strlen(d->line)));
}
@ -261,9 +263,10 @@ interpret(val, len)
if (d == 0)
return (0);
(void) strncpy(d->line, val, len);
(void) strncpy(d->line, val, BUFSIZ);
d->line[BUFSIZ] = '\0';
p = d->line;
d->line[len] = '\n';
p[len] = '\n';
if (*p == '#')
return (getrpcent());
cp = strpbrk(p, "#\n");