Source-Changes-HG archive

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

[src/trunk]: src/lib/libpam/modules/pam_krb5 lib/libpam: Fix the possible -We...



details:   https://anonhg.NetBSD.org/src/rev/a2c84c376b79
branches:  trunk
changeset: 972864:a2c84c376b79
user:      fox <fox%NetBSD.org@localhost>
date:      Fri Jun 12 01:20:32 2020 +0000

description:
lib/libpam: Fix the possible -Werror=stringop-truncation

Replace strncpy(3) with the safer strlcpy(3) and adjust the code.

Error was reported when build.sh was run with MKLIBCSANITIZER=yes flag.

Reviewed by: kamil@, christos@

diffstat:

 lib/libpam/modules/pam_krb5/pam_krb5.c |  9 ++++-----
 1 files changed, 4 insertions(+), 5 deletions(-)

diffs (30 lines):

diff -r 89928b9d38a1 -r a2c84c376b79 lib/libpam/modules/pam_krb5/pam_krb5.c
--- a/lib/libpam/modules/pam_krb5/pam_krb5.c    Fri Jun 12 00:02:26 2020 +0000
+++ b/lib/libpam/modules/pam_krb5/pam_krb5.c    Fri Jun 12 01:20:32 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pam_krb5.c,v 1.28 2020/02/07 23:28:59 christos Exp $   */
+/*     $NetBSD: pam_krb5.c,v 1.29 2020/06/12 01:20:32 fox Exp $        */
 
 /*-
  * This pam_krb5 module contains code that is:
@@ -53,7 +53,7 @@
 #ifdef __FreeBSD__
 __FBSDID("$FreeBSD: src/lib/libpam/modules/pam_krb5/pam_krb5.c,v 1.22 2005/01/24 16:49:50 rwatson Exp $");
 #else
-__RCSID("$NetBSD: pam_krb5.c,v 1.28 2020/02/07 23:28:59 christos Exp $");
+__RCSID("$NetBSD: pam_krb5.c,v 1.29 2020/06/12 01:20:32 fox Exp $");
 #endif
 
 #include <sys/types.h>
@@ -945,9 +945,8 @@
                        return -1;
 
                /* Extract the name directly. */
-               strncpy(phost, compat_princ_component(context, princ, 1),
-                   BUFSIZ);
-               phost[BUFSIZ - 1] = '\0';
+               strlcpy(phost, compat_princ_component(context, princ, 1),
+                   sizeof(phost));
 
                /*
                 * Do we have service/<host> keys?



Home | Main Index | Thread Index | Old Index