Fix null dereference.
authorSascha Wildner <swildner@dragonflybsd.org>
Sat, 23 Aug 2008 23:23:37 +0000 (23:23 +0000)
committerSascha Wildner <swildner@dragonflybsd.org>
Sat, 23 Aug 2008 23:23:37 +0000 (23:23 +0000)
Found-by: LLVM/Clang Static Analyzer
games/robots/score.c

index ba14652..f4f3072 100644 (file)
@@ -32,7 +32,7 @@
  *
  * @(#)score.c 8.1 (Berkeley) 5/31/93
  * $FreeBSD: src/games/robots/score.c,v 1.5 1999/11/30 03:49:20 billf Exp $
- * $DragonFly: src/games/robots/score.c,v 1.3 2006/08/27 21:45:07 pavalos Exp $
+ * $DragonFly: src/games/robots/score.c,v 1.4 2008/08/23 23:23:37 swildner Exp $
  */
 
 # include      "robots.h"
@@ -145,11 +145,11 @@ static void
 set_name(SCORE *scp)
 {
        PASSWD  *pp;
-       static char     unk[] = "???";
 
        if ((pp = getpwuid(scp->s_uid)) == NULL)
-               pp->pw_name = unk;
-       strncpy(scp->s_name, pp->pw_name, MAXNAME);
+               strncpy(scp->s_name, "???", MAXNAME);
+       else
+               strncpy(scp->s_name, pp->pw_name, MAXNAME);
 }
 
 /*