RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 2072329 - mbsrtowcs and mbsnrtowcs fortification should be skipped for NULL __dst [rhl-8.7.0]
Summary: mbsrtowcs and mbsnrtowcs fortification should be skipped for NULL __dst [rhl-...
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 8
Classification: Red Hat
Component: glibc
Version: 8.7
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: rc
: ---
Assignee: Siddhesh Poyarekar
QA Contact: Martin Coufal
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2022-04-06 02:45 UTC by Siddhesh Poyarekar
Modified: 2023-07-18 14:30 UTC (History)
8 users (show)

Fixed In Version: glibc-2.28-199.el8
Doc Type: No Doc Update
Doc Text:
Clone Of:
Environment:
Last Closed: 2022-11-08 10:43:12 UTC
Type: Bug
Target Upstream Version:
Embargoed:
pm-rhel: mirror+


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Issue Tracker RHELPLAN-117990 0 None None None 2022-04-06 02:52:00 UTC
Red Hat Product Errata RHBA-2022:7684 0 None None None 2022-11-08 10:43:40 UTC
Sourceware 29030 0 P2 NEW GLIBC 2.35 regression - Fortify crash on certain valid uses of mbsrtowcs (*** buffer overflow detected ***: terminated) 2022-04-06 02:45:54 UTC

Description Siddhesh Poyarekar 2022-04-06 02:45:54 UTC
Description of problem:
One of the patches backported for bug 2033684 results in a regression for mbsrtowcs where providing a NULL destination should result in the input length being ignored, but it isn't.

Version-Release number of selected component (if applicable):
glibc-2.28-194.el8

How reproducible:
Always

Steps to Reproduce:

$ cat > test.c
    #include <wchar.h>

    int main (void)
    {
        const char *hw = "HelloWorld";
        mbsrtowcs (NULL, &hw, (size_t)-1, NULL);
        return 0;
    }

$ gcc -O2 -Wp,-D_FORTIFY_SOURCE=2 test.c -o test && ./test

Actual results:
    In file included from /usr/include/features.h:490,
                     from /usr/include/bits/libc-header-start.h:33,
                     from /usr/include/wchar.h:27,
                     from test.c:1:
    In function 'mbsrtowcs',
        inlined from 'main' at test.c:6:9:
    /usr/include/bits/wchar2.h:428:10: warning: call to '__mbsrtowcs_chk_warn' declared with attribute warning: mbsrtowcs called with dst buffer smaller than len * sizeof (wchar_t) [-Wattribute-warning]
      428 |   return __glibc_fortify_n (mbsrtowcs, __len, sizeof (wchar_t),
          |          ^~~~~~~~~~~~~~~~~

Expected results:
No warnings and no crash.

Additional info:

Comment 1 Carlos O'Donell 2022-04-06 17:04:38 UTC
When fixing mbstowcs we had the same issue.

I noted this in commit 61af4bbb2ae5a4eefc4c4243135747bbdb0f0684
    
    The mbsrtowcs and mbsnrtowcs behave similarly, and mbsrtowcs is
    documented as doing this in C11, even if the standard doesn't come out
    and call out this specific use case.  We add one note to each of
    mbsrtowcs and mbsnrtowcs to call out that they support a null pointer
    for the destination.

... but I didn't extend the test case to cover these, sorry!

Comment 8 errata-xmlrpc 2022-11-08 10:43:12 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (glibc bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2022:7684


Note You need to log in before you can comment on or make changes to this bug.