Date: Fri, 4 Jul 2003 17:33:36 +0200 (CEST) From: Stefan Farfeleder <stefan@fafoe.narf.at> To: FreeBSD-gnats-submit@FreeBSD.org Cc: ken@FreeBSD.org Subject: bin/54098: [patch] make camcontrol(8) work if plain char is unsigned Message-ID: <20030704153336.9C751851@frog.fafoe.narf.at> Resent-Message-ID: <200307041540.h64FeA6t064957@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>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:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030704153336.9C751851>