From stefan@fafoe.dyndns.org  Fri Jul  4 08:33:39 2003
Return-Path: <stefan@fafoe.dyndns.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP
	id 40DB637B401; Fri,  4 Jul 2003 08:33:39 -0700 (PDT)
Received: from fafoe.narf.at (chello212186121237.14.vie.surfer.at [212.186.121.237])
	by mx1.FreeBSD.org (Postfix) with ESMTP
	id 83B2743FE1; Fri,  4 Jul 2003 08:33:38 -0700 (PDT)
	(envelope-from stefan@fafoe.dyndns.org)
Received: from frog.fafoe.narf.at (frog.fafoe.narf.at [192.168.2.101])
	by fafoe.narf.at (Postfix) with ESMTP
	id 125743FAA; Fri,  4 Jul 2003 17:33:37 +0200 (CEST)
Received: by frog.fafoe.narf.at (Postfix, from userid 1001)
	id 9C751851; Fri,  4 Jul 2003 17:33:36 +0200 (CEST)
Message-Id: <20030704153336.9C751851@frog.fafoe.narf.at>
Date: Fri,  4 Jul 2003 17:33:36 +0200 (CEST)
From: Stefan Farfeleder <stefan@fafoe.narf.at>
Reply-To: Stefan Farfeleder <stefan@fafoe.narf.at>
To: FreeBSD-gnats-submit@freebsd.org
Cc: ken@FreeBSD.org, stefan@fafoe.narf.at
Subject: [patch] make camcontrol(8) work if plain char is unsigned
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         54098
>Category:       bin
>Synopsis:       [patch] make camcontrol(8) work if plain char is unsigned
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    grehan
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Jul 04 08:40:10 PDT 2003
>Closed-Date:    Thu Jan 22 20:49:47 PST 2004
>Last-Modified:  Thu Jan 22 20:49:47 PST 2004
>Originator:     Stefan Farfeleder
>Release:        FreeBSD 5.1-CURRENT i386
>Organization:
>Environment:
System: FreeBSD frog.fafoe.narf.at 5.1-CURRENT FreeBSD 5.1-CURRENT #19: Fri Jul 4 14:44:41 CEST 2003 freebsd@frog.fafoe.narf.at:/freebsd/frog/obj/freebsd/frog/src/sys/FROG i386


	
>Description:
Camcontrol(8) contains the following bug:

char c;
while ((c = fgetc(f)) != EOF)
...

If char is an unsigned type, EOF from fgetc() will be wrapped to CHAR_MAX on
assignment and c will never equal EOF which leads to an endless loop.

	
>How-To-Repeat:
	
>Fix:
An additional int variable ch holds the value from fgetc() for comparisons with
EOF.  c can't have type int itself because its address is passed to strncat()
later.
	

--- camcontrol.diff begins here ---
Index: src/sbin/camcontrol/modeedit.c
===================================================================
RCS file: /usr/home/ncvs/src/sbin/camcontrol/modeedit.c,v
retrieving revision 1.14
diff -u -r1.14 modeedit.c
--- src/sbin/camcontrol/modeedit.c	2 May 2003 06:49:10 -0000	1.14
+++ src/sbin/camcontrol/modeedit.c	4 Jul 2003 14:59:21 -0000
@@ -365,6 +365,7 @@
 	int found;
 	int lineno;
 	enum { LOCATE, PAGENAME, PAGEDEF } state;
+	int ch;
 	char c;
 
 #define	SETSTATE_LOCATE do {						\
@@ -400,19 +401,20 @@
 	lineno = 0;
 	found = 0;
 	SETSTATE_LOCATE;
-	while ((c = fgetc(pagedb)) != EOF) {
+	while ((ch = fgetc(pagedb)) != EOF) {
 
 		/* Keep a line count to make error messages more useful. */
 		UPDATE_LINENO;
 
 		/* Skip over comments anywhere in the mode database. */
-		if (c == '#') {
+		if (ch == '#') {
 			do {
-				c = fgetc(pagedb);
-			} while (c != '\n' && c != EOF);
+				ch = fgetc(pagedb);
+			} while (ch != '\n' && ch != EOF);
 			UPDATE_LINENO;
 			continue;
 		}
+		c = ch;
 
 		/* Strip out newline characters. */
 		if (c == '\n')
--- camcontrol.diff ends here ---


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->ken 
Responsible-Changed-By: kris 
Responsible-Changed-When: Fri Jul 18 15:06:20 PDT 2003 
Responsible-Changed-Why:  
Assign to camcontrol maintainer 

http://www.freebsd.org/cgi/query-pr.cgi?pr=54098 
State-Changed-From-To: open->closed  
State-Changed-By: grehan 
State-Changed-When: Thu Jan 22 20:48:46 PST 2004 
State-Changed-Why:  
Fixed as part of the PPC signed-char commit, Jan 22 04. 


Responsible-Changed-From-To: ken->grehan  
Responsible-Changed-By: grehan 
Responsible-Changed-When: Thu Jan 22 20:48:46 PST 2004 
Responsible-Changed-Why:  
Fixed as part of the PPC signed-char commit, Jan 22 04. 

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