From mjl@luckie.org.nz  Mon May 19 07:26:22 2008
Return-Path: <mjl@luckie.org.nz>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 0DAA11065670
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 19 May 2008 07:26:22 +0000 (UTC)
	(envelope-from mjl@luckie.org.nz)
Received: from mailfilter13.ihug.co.nz (mailfilter13.ihug.co.nz [203.109.136.13])
	by mx1.freebsd.org (Postfix) with ESMTP id A93CD8FC2C
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 19 May 2008 07:26:20 +0000 (UTC)
	(envelope-from mjl@luckie.org.nz)
Received: from 118-93-121-155.dsl.dyn.ihug.co.nz (HELO spandex.luckie.org.nz) ([118.93.121.155])
  by smtp.mailfilter5.ihug.co.nz with ESMTP/TLS/DHE-RSA-AES256-SHA; 19 May 2008 19:26:18 +1200
Received: from mjl by spandex.luckie.org.nz with local (Exim 4.69 (FreeBSD))
	(envelope-from <mjl@luckie.org.nz>)
	id 1JxzlC-000G7f-E0
	for FreeBSD-gnats-submit@freebsd.org; Mon, 19 May 2008 19:26:18 +1200
Message-Id: <E1JxzlC-000G7f-E0@spandex.luckie.org.nz>
Date: Mon, 19 May 2008 19:26:18 +1200
From: Matthew Luckie <mjl@luckie.org.nz>
Reply-To: Matthew Luckie <mjl@luckie.org.nz>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [patch] timed does not run on arm (incorrect getopt usage)
X-Send-Pr-Version: 3.113
X-GNATS-Notify: keramida@FreeBSD.org

>Number:         123807
>Category:       bin
>Synopsis:       [patch] timed(8) does not run on arm (incorrect getopt usage)
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    imp
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon May 19 07:30:07 UTC 2008
>Closed-Date:    Fri May 13 14:49:27 MDT 2011
>Last-Modified:  Fri May 13 14:49:27 MDT 2011
>Originator:     Matthew Luckie
>Release:        FreeBSD 7.0-RELEASE-p1 arm
>Organization:
>Environment:
System: FreeBSD vinyl.luckie.org.nz 7.0-RELEASE-p1 FreeBSD 7.0-RELEASE-p1 #4: Sun May 18 08:49:48 NZST 2008     root@rayon.luckie.org.nz:/usr/obj/arm/usr/src/sys/vinyl  arm
>Description:
getopt returns an integer, -1 when there is no further options to parse.
char on arm is an unsigned byte value, so it cannot hold -1.
therefore the getopt hack to hold the return value in a char and loop on that
will fail and leave the application in an infinite loop
>How-To-Repeat:
run timed on systems where char is unsigned.
>Fix:

	

--- patch-timed.c begins here ---
--- usr.sbin/timed/timed/timed.c.orig	2003-07-06 22:37:00.000000000 +1200
+++ usr.sbin/timed/timed/timed.c	2008-05-19 19:14:26.000000000 +1200
@@ -134,7 +134,7 @@ main(argc, argv)
 	struct nets *nt;
 	struct sockaddr_in server;
 	u_short port;
-	char c;
+	int c;
 
 #ifdef lint
 	ntip = NULL;
@@ -147,7 +147,7 @@ main(argc, argv)
 
 	opterr = 0;
 	while ((c = getopt(argc, argv, "Mtdn:i:F:G:P:")) != -1) {
-		switch (c) {
+		switch ((char)c) {
 		case 'M':
 			Mflag = 1;
 			break;
--- patch-timed.c ends here ---


>Release-Note:
>Audit-Trail:

From: Giorgos Keramidas <keramida@freebsd.org>
To: Matthew Luckie <mjl@luckie.org.nz>
Cc: bug-followup@freebsd.org
Subject: Re: bin/123807: [patch] timed does not run on arm (incorrect getopt usage)
Date: Mon, 26 May 2008 12:09:25 +0300

 On Mon, 19 May 2008 19:26:18 +1200, Matthew Luckie <mjl@luckie.org.nz> wrote:
 > getopt returns an integer, -1 when there is no further options to
 > parse.  char on arm is an unsigned byte value, so it cannot hold -1.
 > therefore the getopt hack to hold the return value in a char and loop
 > on that will fail and leave the application in an infinite loop
 
 > --- patch-timed.c begins here ---
 > --- usr.sbin/timed/timed/timed.c.orig	2003-07-06 22:37:00.000000000 +1200
 > +++ usr.sbin/timed/timed/timed.c	2008-05-19 19:14:26.000000000 +1200
 > @@ -134,7 +134,7 @@ main(argc, argv)
 >  	struct nets *nt;
 >  	struct sockaddr_in server;
 >  	u_short port;
 > -	char c;
 > +	int c;
 >
 >  #ifdef lint
 >  	ntip = NULL;
 > @@ -147,7 +147,7 @@ main(argc, argv)
 >
 >  	opterr = 0;
 >  	while ((c = getopt(argc, argv, "Mtdn:i:F:G:P:")) != -1) {
 > -		switch (c) {
 > +		switch ((char)c) {
 >  		case 'M':
 >  			Mflag = 1;
 >  			break;
 > --- patch-timed.c ends here ---
 
 The first hunk of the patch looks ok, but do we really need the second
 one too?  There are far too many places where an `int' return from
 getopt() is compared with '?'-style characters in switch(), so if we
 don't need it let's not add a cast.
 

From: Matthew Luckie <mjl@luckie.org.nz>
To: Giorgos Keramidas <keramida@freebsd.org>
Cc: bug-followup@freebsd.org
Subject: Re: bin/123807: [patch] timed does not run on arm (incorrect getopt
 usage)
Date: Sun, 01 Jun 2008 17:23:33 +1200

 > The first hunk of the patch looks ok, but do we really need the second
 > one too?  There are far too many places where an `int' return from
 > getopt() is compared with '?'-style characters in switch(), so if we
 > don't need it let's not add a cast.
 
 you're right, the cast is not required.

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/123807: commit references a PR
Date: Mon,  2 Jun 2008 04:51:01 +0000 (UTC)

 imp         2008-06-02 04:50:56 UTC
 
   FreeBSD src repository
 
   Modified files:
     usr.sbin/timed/timed timed.c 
   Log:
   SVN rev 179485 on 2008-06-02 04:50:47Z by imp
   
   getopt returns an int, not a char.  Make sure that we store the
   variable in an int to avoid casting to an unsigned value which causes
   the comparison with -1 to fail.
   
   PR:             123807
   Submitted by:   Matthew Luckie
   Reviewed by:    keramida@
   MFC after:      1 week
   
   Revision  Changes    Path
   1.12      +1 -1      src/usr.sbin/timed/timed/timed.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: open->patched 
State-Changed-By: keramida 
State-Changed-When: Tue Jun 3 03:17:07 UTC 2008 
State-Changed-Why:  
Committed to HEAD.  I'm assigning this to Warner, 
so he can merge to the STABLE branches. 


Responsible-Changed-From-To: freebsd-bugs->imp 
Responsible-Changed-By: keramida 
Responsible-Changed-When: Tue Jun 3 03:17:07 UTC 2008 
Responsible-Changed-Why:  

http://www.freebsd.org/cgi/query-pr.cgi?pr=123807 
State-Changed-From-To: patched->closed 
State-Changed-By: imp 
State-Changed-When: Fri May 13 14:49:12 MDT 2011 
State-Changed-Why:  
I think this is done. 

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