From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 00D45385841C; Tue, 9 Apr 2024 13:31:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 00D45385841C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1712669504; bh=E1pSfFHj04MGsuDnOqB75EKag6O/rwCnC7jiiFh+sns=; h=From:To:Subject:Date:In-Reply-To:References:From; b=gTQP6g/XYdHWpqJDoDzH8GFhYl/RI7EzF30KlZIGGmOCUxLLxd0ieTTRVxaotjQ47 IsUJmcrGHgyXjkug7LNEkCLpoDxPfrKHI9CPQKIeLP6Fgjkg0eidj0J/9peoh+r+/K 4VE4GFQ7LE4VXz16p1QCyOU3J3i2NtdWTa15pr+0= From: "email at arsoftware dot net.br" To: bzip2-devel@sourceware.org Subject: [Bug bzip2/28283] undefined behavior for isdigit and isspace Date: Tue, 09 Apr 2024 13:31:42 +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: email at arsoftware dot net.br 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: 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 --- Comment #3 from email at arsoftware dot net.br --- Em 2022-12-27 14:24, mark at klomp dot org via Bzip2-devel escreveu: > https://sourceware.org/bugzilla/show_bug.cgi?id=3D28283 >=20 > Mark Wielaard changed: >=20 > What |Removed |Added > -------------------------------------------------------------------------= --- > CC| |mark at klomp dot org >=20 > --- Comment #2 from Mark Wielaard --- > So both cases the chars tested are user supplied and could in theory be=20 > signed > chars. So casting to Int32 or int could create negative values. Which=20 > isspace > and isdigit don't handle. Proposed patch: >=20 > 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*=20 > varName ) > 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; > } > } yes, I agree ric --=20 You are receiving this mail because: You are on the CC list for the bug.=