From owner-freebsd-bugs@FreeBSD.ORG Fri Jul 4 08:40:12 2003 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 03B7937B401 for ; Fri, 4 Jul 2003 08:40:12 -0700 (PDT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id A3F7643FF5 for ; Fri, 4 Jul 2003 08:40:10 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.9/8.12.9) with ESMTP id h64FeAUp064958 for ; Fri, 4 Jul 2003 08:40:10 -0700 (PDT) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.9/8.12.9/Submit) id h64FeA6t064957; Fri, 4 Jul 2003 08:40:10 -0700 (PDT) Resent-Date: Fri, 4 Jul 2003 08:40:10 -0700 (PDT) Resent-Message-Id: <200307041540.h64FeA6t064957@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Stefan Farfeleder 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 To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 cc: stefan@fafoe.narf.at cc: ken@FreeBSD.org Subject: bin/54098: [patch] make camcontrol(8) work if plain char is unsigned X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: Stefan Farfeleder List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 04 Jul 2003 15:40:12 -0000 >Number: 54098 >Category: bin >Synopsis: [patch] make camcontrol(8) work if plain char is unsigned >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Fri Jul 04 08:40:10 PDT 2003 >Closed-Date: >Last-Modified: >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: >Unformatted: