Source-Changes-HG archive

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

[src/trunk]: src/lib/libc/gen getlogin_r: use strcpy(). We check namelen bef...



details:   https://anonhg.NetBSD.org/src/rev/c255672d3e84
branches:  trunk
changeset: 845543:c255672d3e84
user:      uwe <uwe%NetBSD.org@localhost>
date:      Sat Oct 05 19:19:51 2019 +0000

description:
getlogin_r: use strcpy().  We check namelen before copying the result.
gcc 8 -Wstringop-overflow is uhappy when the specified bounds depend
on the length of the source and is not smart enough to see the check
we do.  Besides we don't want the padding effect of strncpy() here.

diffstat:

 lib/libc/gen/getlogin.c |  6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diffs (27 lines):

diff -r ebf3a2d542aa -r c255672d3e84 lib/libc/gen/getlogin.c
--- a/lib/libc/gen/getlogin.c   Sat Oct 05 18:37:39 2019 +0000
+++ b/lib/libc/gen/getlogin.c   Sat Oct 05 19:19:51 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: getlogin.c,v 1.15 2009/01/11 02:46:27 christos Exp $   */
+/*     $NetBSD: getlogin.c,v 1.16 2019/10/05 19:19:51 uwe Exp $        */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
 #if 0
 static char sccsid[] = "@(#)getlogin.c 8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: getlogin.c,v 1.15 2009/01/11 02:46:27 christos Exp $");
+__RCSID("$NetBSD: getlogin.c,v 1.16 2019/10/05 19:19:51 uwe Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -126,7 +126,7 @@
        if (len > namelen) {
                rv = ERANGE;
        } else {
-               strncpy(name, logname, len);
+               strcpy(name, logname);
                rv = 0;
        }
        mutex_unlock(&logname_mutex);



Home | Main Index | Thread Index | Old Index