From nobody@FreeBSD.org  Wed Oct 10 10:50:28 2012
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52])
	by hub.freebsd.org (Postfix) with ESMTP id 47D96136
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 10 Oct 2012 10:50:28 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id 17E758FC20
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 10 Oct 2012 10:50:28 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.5/8.14.5) with ESMTP id q9AAoRsD087428
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 10 Oct 2012 10:50:27 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.5/8.14.5/Submit) id q9AAoRbe087427;
	Wed, 10 Oct 2012 10:50:27 GMT
	(envelope-from nobody)
Message-Id: <201210101050.q9AAoRbe087427@red.freebsd.org>
Date: Wed, 10 Oct 2012 10:50:27 GMT
From: Erik Cederstrand <erik@cederstrand.dk>
To: freebsd-gnats-submit@FreeBSD.org
Subject: Fix analyzer warnings in /games
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         172566
>Category:       bin
>Synopsis:       Fix analyzer warnings in /games
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    eadler
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Oct 10 11:00:00 UTC 2012
>Closed-Date:    Sun Feb 03 03:47:41 UTC 2013
>Last-Modified:  Sun Feb 03 03:47:41 UTC 2013
>Originator:     Erik Cederstrand
>Release:        CURRENT
>Organization:
>Environment:
>Description:
Fix 4 warnings in /games reported by Clang Static Analyzer: 

bcd and caesar are not installed SETGID (at least on my system). Remove the call to setgid() as it becomes redundant.

In fortune, make sure a tail file is passed in the args if mandated in the logic. Bail if not.

In random(6), fix a memory leak in randomize_fd()
>How-To-Repeat:

>Fix:
Se attached patch

Patch attached with submission follows:

Index: head/games/random/randomize_fd.c
===================================================================
--- head/games/random/randomize_fd.c	(revision 241370)
+++ head/games/random/randomize_fd.c	(working copy)
@@ -207,6 +207,7 @@
 		goto make_token;
 	}
 
+	free(buf);
 	for (i = numnode; i > 0; i--) {
 		selected = random() % numnode;
 
Index: head/games/fortune/fortune/fortune.c
===================================================================
--- head/games/fortune/fortune/fortune.c	(revision 241370)
+++ head/games/fortune/fortune/fortune.c	(working copy)
@@ -576,6 +576,10 @@
 	if (*head == NULL)
 		*head = *tail = fp;
 	else if (fp->percent == NO_PROB) {
+		if (*tail == NULL) {
+			fprintf(stderr, "No tail file given\n");
+			exit(1);
+		}
 		(*tail)->next = fp;
 		fp->prev = *tail;
 		*tail = fp;
Index: head/games/bcd/bcd.c
===================================================================
--- head/games/bcd/bcd.c	(revision 241370)
+++ head/games/bcd/bcd.c	(working copy)
@@ -129,9 +129,6 @@
 {
 	char cardline[80];
 
-	/* revoke setgid privileges */
-	setgid(getgid());
-
 	/*
 	 * The original bcd prompts with a "%" when reading from stdin,
 	 * but this seems kind of silly.  So this one doesn't.
Index: head/games/caesar/caesar.c
===================================================================
--- head/games/caesar/caesar.c	(revision 241370)
+++ head/games/caesar/caesar.c	(working copy)
@@ -82,9 +82,6 @@
 	char *inbuf;
 	int obs[26], try, winner;
 
-	/* revoke setgid privileges */
-	setgid(getgid());
-
 	if (argc > 1)
 		printit(argv[1]);

>Release-Note:
>Audit-Trail:

From: Erik Cederstrand <erik@cederstrand.dk>
To: FreeBSD-gnats-submit@FreeBSD.org,
 freebsd-bugs@FreeBSD.org
Cc:  
Subject: Re: misc/172566: Fix analyzer warnings in /games
Date: Wed, 10 Oct 2012 13:20:42 +0200

 Den 10/10/2012 kl. 13.00 skrev FreeBSD-gnats-submit@freebsd.org:
 
 >> Category:       misc
 >> Responsible:    freebsd-bugs
 >> Synopsis:       Fix analyzer warnings in /games
 >> Arrival-Date:   Wed Oct 10 11:00:00 UTC 2012
 
 Forgot to link to the reports: =
 http://scan.freebsd.your.org/freebsd-head/games/2012-10-07-amd64/
 
 Erik=
Responsible-Changed-From-To: freebsd-bugs->eadler 
Responsible-Changed-By: eadler 
Responsible-Changed-When: Wed Oct 10 12:37:09 UTC 2012 
Responsible-Changed-Why:  
I'll take it. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=172566 
State-Changed-From-To: open->analyzed 
State-Changed-By: eadler 
State-Changed-When: Sat Oct 13 04:45:43 UTC 2012 
State-Changed-Why:  
I've submitted changes for bcd, caesar, and random. fortune appears to 
be a false positive - although an assert might help. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=172566 

From: Erik Cederstrand <erik@cederstrand.dk>
To: bug-followup@FreeBSD.org,
 erik@cederstrand.dk
Cc:  
Subject: Re: bin/172566: Fix analyzer warnings in /games
Date: Mon, 22 Oct 2012 13:18:55 +0200

 --Apple-Mail=_D17A8712-2E41-4752-AB26-E8BD3DF90E7A
 Content-Transfer-Encoding: 7bit
 Content-Type: text/plain;
 	charset=us-ascii
 
 Here's a new patch for fortune with an assert() instead.
 
 Thanks,
 Erik
 
 --Apple-Mail=_D17A8712-2E41-4752-AB26-E8BD3DF90E7A
 Content-Disposition: attachment;
 	filename=fortune.txt
 Content-Type: text/plain;
 	x-unix-mode=0644;
 	name="fortune.txt"
 Content-Transfer-Encoding: 7bit
 
 Index: head/games/fortune/fortune/fortune.c
 ===================================================================
 --- head/games/fortune/fortune/fortune.c (revision 241876)
 +++ head/games/fortune/fortune/fortune.c (working copy)
 @@ -576,6 +576,7 @@
         if (*head == NULL)
                 *head = *tail = fp;
         else if (fp->percent == NO_PROB) {
 +               assert(*tail);
                 (*tail)->next = fp;
                 fp->prev = *tail;
                 *tail = fp;
 
 --Apple-Mail=_D17A8712-2E41-4752-AB26-E8BD3DF90E7A--
State-Changed-From-To: analyzed->patched 
State-Changed-By: eadler 
State-Changed-When: Thu Oct 25 23:24:19 UTC 2012 
State-Changed-Why:  
committed in HEAD 

http://www.freebsd.org/cgi/query-pr.cgi?pr=172566 
State-Changed-From-To: patched->closed 
State-Changed-By: eadler 
State-Changed-When: Sun Feb 3 03:47:40 UTC 2013 
State-Changed-Why:  
I shall not MFC this PR 

http://www.freebsd.org/cgi/query-pr.cgi?pr=172566 
>Unformatted:
