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/5290191bc981
branches:  trunk
changeset: 961595:5290191bc981
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 29f50ea6198a -r 5290191bc981 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 @@
 
        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