Source-Changes-HG archive

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

[src/trunk]: src/games/robots properly terminate after using strncpy().



details:   https://anonhg.NetBSD.org/src/rev/3accc88e6c5d
branches:  trunk
changeset: 961602:3accc88e6c5d
user:      mrg <mrg%NetBSD.org@localhost>
date:      Tue Apr 13 01:50:46 2021 +0000

description:
properly terminate after using strncpy().

diffstat:

 games/robots/score.c |  9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)

diffs (31 lines):

diff -r c5d6cd66e3ca -r 3accc88e6c5d games/robots/score.c
--- a/games/robots/score.c      Tue Apr 13 01:38:04 2021 +0000
+++ b/games/robots/score.c      Tue Apr 13 01:50:46 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: score.c,v 1.23 2009/08/12 08:30:55 dholland Exp $      */
+/*     $NetBSD: score.c,v 1.24 2021/04/13 01:50:46 mrg Exp $   */
 
 /*
  * Copyright (c) 1980, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)score.c    8.1 (Berkeley) 5/31/93";
 #else
-__RCSID("$NetBSD: score.c,v 1.23 2009/08/12 08:30:55 dholland Exp $");
+__RCSID("$NetBSD: score.c,v 1.24 2021/04/13 01:50:46 mrg Exp $");
 #endif
 #endif /* not lint */
 
@@ -198,9 +198,10 @@
        struct passwd *pp;
 
        if ((pp = getpwuid(scp->s_uid)) == NULL)
-               strncpy(scp->s_name, "???", MAXNAME);
+               strncpy(scp->s_name, "???", MAXNAME - 1);
        else
-               strncpy(scp->s_name, pp->pw_name, MAXNAME);
+               strncpy(scp->s_name, pp->pw_name, MAXNAME - 1);
+       scp->s_name[MAXNAME - 1] = '\0';
 }
 
 /*



Home | Main Index | Thread Index | Old Index