From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id D64003858400; Mon, 18 Jul 2022 21:19:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D64003858400 From: "msebor at gmail dot com" To: glibc-bugs@sourceware.org Subject: [Bug stdio/29379] New: snprintf with n greater than INT_MAX succeeds and doesn't set errno Date: Mon, 18 Jul 2022 21:19:37 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: glibc X-Bugzilla-Component: stdio X-Bugzilla-Version: unspecified X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: msebor at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: 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 X-BeenThere: glibc-bugs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Glibc-bugs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 18 Jul 2022 21:19:38 -0000 https://sourceware.org/bugzilla/show_bug.cgi?id=3D29379 Bug ID: 29379 Summary: snprintf with n greater than INT_MAX succeeds and doesn't set errno Product: glibc Version: unspecified Status: UNCONFIRMED Severity: normal Priority: P2 Component: stdio Assignee: unassigned at sourceware dot org Reporter: msebor at gmail dot com Target Milestone: --- As an extension to C, POSIX specifies that The snprintf() function shall fail if: [EOVERFLOW] [CX]The value of n is greater than {INT_MAX}. Compiling the following test case with GCC produces a couple of warnings th= at are meant to point this out, but running it on Linux doesn't result in the expected output: the call doesn't return a negative value and errno is not = set to EOVERFLOW. $ cat a.c && gcc -O -Wall a.c && ./a.out #include #include #include char s[] =3D "123"; const size_t m1 =3D -1; const size_t imaxp1 =3D INT_MAX + (size_t)1; int main (void) { char a[sizeof s]; errno =3D 0; int n =3D snprintf (a, m1, s); printf ("%i (%m)\n", n); errno =3D 0; n =3D snprintf (a, imaxp1, s); printf ("%i (%m)\n", n); } a.c: In function =E2=80=98main=E2=80=99: a.c:14:11: warning: specified bound 18446744073709551615 exceeds maximum ob= ject size 9223372036854775807 [-Wformat-truncation=3D] 14 | int n =3D snprintf (a, m1, s); | ^~~~~~~~~~~~~~~~~~~ a.c:18:7: warning: specified bound 2147483648 exceeds =E2=80=98INT_MAX=E2= =80=99 [-Wformat-truncation=3D] 18 | n =3D snprintf (a, imaxp1, s); | ^~~~~~~~~~~~~~~~~~~~~~~ 3 (Success) 3 (Success) --=20 You are receiving this mail because: You are on the CC list for the bug.=