From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id B087D3858D39; Tue, 27 Dec 2022 17:24:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B087D3858D39 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1672161865; bh=8XNLakWqDQpvonwvRYO1CwMl2kiOCebrl3++VDOrkBY=; h=From:To:Subject:Date:In-Reply-To:References:From; b=wOVAnpa2pXuivYQ7YxxXL0hrdSB8Az48MYQCUjsowospzYjT6WyLY3TsiCkDzTRnl 9wzHqNB2xh5eiIUc8E6Kn3w7a2FlxwEZ8a7pSXQTpHqaJ6471hG1+aiXzF9QCYiryD lVxdwT0v9CNt3+HEz+iiG3olxGIoCjcvU+MTHOFs= From: "mark at klomp dot org" To: bzip2-devel@sourceware.org Subject: [Bug bzip2/28283] undefined behavior for isdigit and isspace Date: Tue, 27 Dec 2022 17:24:25 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: bzip2 X-Bugzilla-Component: bzip2 X-Bugzilla-Version: unspecified X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: mark at klomp dot org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: nobody at sourceware dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cc Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://sourceware.org/bugzilla/show_bug.cgi?id=3D28283 Mark Wielaard changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |mark at klomp dot org --- Comment #2 from Mark Wielaard --- So both cases the chars tested are user supplied and could in theory be sig= ned chars. So casting to Int32 or int could create negative values. Which isspa= ce and isdigit don't handle. Proposed patch: diff --git a/bzip2.c b/bzip2.c index 1538faf..9ef7536 100644 --- a/bzip2.c +++ b/bzip2.c @@ -1767,8 +1767,8 @@ void addFlagsFromEnvVar ( Cell** argList, Char* varNa= me ) if (p[i] =3D=3D 0) break; p +=3D i; i =3D 0; - while (isspace((Int32)(p[0]))) p++; - while (p[i] !=3D 0 && !isspace((Int32)(p[i]))) i++; + while (isspace((UChar)(p[0]))) p++; + while (p[i] !=3D 0 && !isspace((UChar)(p[i]))) i++; if (i > 0) { k =3D i; if (k > FILE_NAME_LEN-10) k =3D FILE_NAME_LEN-10; for (j =3D 0; j < k; j++) tmpName[j] =3D p[j]; diff --git a/bzlib.c b/bzlib.c index 2178655..100873c 100644 --- a/bzlib.c +++ b/bzlib.c @@ -1408,7 +1408,7 @@ BZFILE * bzopen_or_bzdopen case 's': smallMode =3D 1; break; default: - if (isdigit((int)(*mode))) { + if (isdigit((unsigned char)(*mode))) { blockSize100k =3D *mode-BZ_HDR_0; } } --=20 You are receiving this mail because: You are on the CC list for the bug.=