summaryrefslogtreecommitdiff
path: root/lib/libc/rpc/getrpcent.c
diff options
context:
space:
mode:
authorThorsten Lockert <tholo@cvs.openbsd.org>1996-09-02 05:32:51 +0000
committerThorsten Lockert <tholo@cvs.openbsd.org>1996-09-02 05:32:51 +0000
commit692db736236edb8012df8cdfa06cb4e2fdbc1813 (patch)
treea0f3f258c34e8ca6d76e9166be20a23b564c6229 /lib/libc/rpc/getrpcent.c
parent4e8a89b3a43bc25f94016f52d44dbedf9b4a788b (diff)
Don't overwrite the last byte of a line unless we have to
Diffstat (limited to 'lib/libc/rpc/getrpcent.c')
-rw-r--r--lib/libc/rpc/getrpcent.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/lib/libc/rpc/getrpcent.c b/lib/libc/rpc/getrpcent.c
index 185dd757a3a..157ad672cca 100644
--- a/lib/libc/rpc/getrpcent.c
+++ b/lib/libc/rpc/getrpcent.c
@@ -29,7 +29,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char *rcsid = "$OpenBSD: getrpcent.c,v 1.5 1996/09/02 02:48:57 deraadt Exp $";
+static char *rcsid = "$OpenBSD: getrpcent.c,v 1.6 1996/09/02 05:32:50 tholo Exp $";
#endif /* LIBC_SCCS and not lint */
/*
@@ -150,7 +150,8 @@ getrpcent()
return(NULL);
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)));
}
@@ -166,10 +167,10 @@ interpret(val, len)
if (d == 0)
return (0);
- (void) strncpy(d->line, val, len-1);
- d->line[len-1] = '\0';
+ (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");