diff options
author | peter <peter@FreeBSD.org> | 1996-12-30 14:42:31 +0000 |
---|---|---|
committer | peter <peter@FreeBSD.org> | 1996-12-30 14:42:31 +0000 |
commit | 2ad3d008149e3d2ce1d9499c67716500e0199649 (patch) | |
tree | eee9b5549de006efa23663646fde0140dfdf335e /lib/libc/rpc | |
parent | acdf726df9abb53422e33ee79f99d1a84e9286c4 (diff) | |
download | FreeBSD-src-2ad3d008149e3d2ce1d9499c67716500e0199649.zip FreeBSD-src-2ad3d008149e3d2ce1d9499c67716500e0199649.tar.gz |
- OpenBSD's strncpy fixes to ensure NULL termination
- missed endrpcent() in some cases.
Obtained from: a diff of FreeBSD vs. OpenBSD/NetBSD rpc code.
Diffstat (limited to 'lib/libc/rpc')
-rw-r--r-- | lib/libc/rpc/getrpcent.c | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/lib/libc/rpc/getrpcent.c b/lib/libc/rpc/getrpcent.c index eb278c0..cb4f703 100644 --- a/lib/libc/rpc/getrpcent.c +++ b/lib/libc/rpc/getrpcent.c @@ -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"); |