Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libc/rpc pass dest buffer size to strncpy() and ensure n...



details:   https://anonhg.NetBSD.org/src/rev/464e97628946
branches:  trunk
changeset: 378423:464e97628946
user:      mrg <mrg%NetBSD.org@localhost>
date:      Tue Apr 13 00:29:22 2021 +0000

description:
pass dest buffer size to strncpy() and ensure nul termination.

diffstat:

 lib/libc/rpc/getrpcent.c |  7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)

diffs (28 lines):

diff -r c289152c51c8 -r 464e97628946 lib/libc/rpc/getrpcent.c
--- a/lib/libc/rpc/getrpcent.c  Mon Apr 12 18:53:51 2021 +0000
+++ b/lib/libc/rpc/getrpcent.c  Tue Apr 13 00:29:22 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: getrpcent.c,v 1.23 2013/03/11 20:19:29 tron Exp $      */
+/*     $NetBSD: getrpcent.c,v 1.24 2021/04/13 00:29:22 mrg Exp $       */
 
 /*
  * Copyright (c) 2010, Oracle America, Inc.
@@ -36,7 +36,7 @@
 #if 0
 static char *sccsid = "@(#)getrpcent.c 1.14 91/03/11 Copyr 1984 Sun Micro";
 #else
-__RCSID("$NetBSD: getrpcent.c,v 1.23 2013/03/11 20:19:29 tron Exp $");
+__RCSID("$NetBSD: getrpcent.c,v 1.24 2021/04/13 00:29:22 mrg Exp $");
 #endif
 #endif
 
@@ -185,7 +185,8 @@ interpret(char *val, size_t len)
 
        if (d == 0)
                return (0);
-       (void) strncpy(d->line, val, len);
+       strncpy(d->line, val, sizeof(d->line) - 1);
+       d->line[sizeof(d->line) - 1] = '\0';
        p = d->line;
        d->line[len] = '\n';
        if (*p == '#')



Home | Main Index | Thread Index | Old Index