Bug 2047715 - gcc-12.0.1: false positive use-after-free error in the libdatovka?
Summary: gcc-12.0.1: false positive use-after-free error in the libdatovka?
Keywords:
Status: CLOSED EOL
Alias: None
Product: Fedora
Classification: Fedora
Component: gcc
Version: 36
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2022-01-28 11:44 UTC by Jaroslav Škarvada
Modified: 2023-05-25 16:51 UTC (History)
11 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2023-05-25 16:51:51 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
GNU Compiler Collection 104232 0 P1 RESOLVED [12 Regression] spurious -Wuse-after-free after conditional free 2022-01-31 23:30:02 UTC

Description Jaroslav Škarvada 2022-01-28 11:44:55 UTC
Description of problem:
gcc-12.0.1 is reporting suspicious warning/error about the use-after-free when compiling libdatovka (without the gcc-12 fix patch).

Version-Release number of selected component (if applicable):
gcc-12.0.1-0.2.fc36

How reproducible:
Always

Steps to Reproduce:
1. git clone https://src.fedoraproject.org/rpms/libdatovka.git
2. cd libdatovka
3. git checkout 13bb00d9ca07713c403dee9924a1de87c3accebe
4. fedpkg --release f36 build

Actual results:
isds.c: In function 'build_send_check_dbdummy_request.part.0.constprop.0':
isds.c:6101:5: error: pointer 'request_37' used after 'free' [-Werror=use-after-free]
 6101 |     xmlFreeNode(request);
      |     ^~~~~~~~~~~~~~~~~~~~
isds.c:6100:5: note: call to 'free' here
 6100 |     free(service_name_locale);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors


Expected results:
No warning/error

Additional info:
Upstream cannot spot any problem with the code, upstream ticket:
https://gitlab.nic.cz/datovka/libdatovka/-/issues/17

Comment 1 Jaroslav Škarvada 2022-01-28 14:44:17 UTC
The same problem with the gcc-12.0.1-0.3.fc36

Comment 2 Petr Pisar 2022-01-31 08:26:01 UTC
I looked at the code and I think this is a bug in GCC. Here is a standalone reproducer:

/* gcc -O1 -pipe -Wuse-after-free=1 -Werror -c test.c -o /dev/null */
#include <stdlib.h>

void *make(void);
void barf(void *);

void function(void) {
    void *cat = NULL;
    void *dog = NULL;

    cat = make();
    if (!cat)
        goto leave;

    dog = make();

leave:
    free(cat);
    barf(dog);
}

$ gcc -O1 -pipe -Wuse-after-free=1 -Werror -c test.c -o /dev/null
test.c: In function ‘function’:
test.c:19:5: error: pointer ‘dog’ used after ‘free’ [-Werror=use-after-free]
   19 |     barf(dog);
      |     ^~~~~~~~~
test.c:18:5: note: call to ‘free’ here
   18 |     free(cat);
      |     ^~~~~~~~~
cc1: all warnings being treated as errors

A trigger is the free() call. Negating the (!cat) condition, making the goto unconditional, or removing the dog = make() assignment disappears the warning.


I silenced this warning in libisds with <https://repo.or.cz/libisds.git/patch/e61d1504456b80121837acb23549bf630c0a19df> where I escape the function before attempting to call free() on the NULL pointer.

Comment 3 Petr Pisar 2022-01-31 08:36:21 UTC
After applying the patch, I got a similar failure elsewhere, but only on s390x and ppc64le <https://koji.fedoraproject.org/koji/taskinfo?taskID=82173494>.

Comment 4 Petr Pisar 2022-01-31 09:34:33 UTC
The architecture-specific issue resolved with this libisds patch <https://repo.or.cz/libisds.git/patch/890d63b43a6aac9f9f5bd83c01f2423aa661c716>.

Comment 5 Martin Sebor 2022-01-31 23:30:02 UTC
The false positive for the test case in comment #2 is tracked in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104232.  The fix for that was committed earlier today.  If that doesn't also resolve the originally reported problem please attach a preprocessing translation unit for the file (the result of compiling with -E).

Comment 6 Ben Cotton 2022-02-08 20:23:26 UTC
This bug appears to have been reported against 'rawhide' during the Fedora 36 development cycle.
Changing version to 36.

Comment 7 Ben Cotton 2023-04-25 16:52:30 UTC
This message is a reminder that Fedora Linux 36 is nearing its end of life.
Fedora will stop maintaining and issuing updates for Fedora Linux 36 on 2023-05-16.
It is Fedora's policy to close all bug reports from releases that are no longer
maintained. At that time this bug will be closed as EOL if it remains open with a
'version' of '36'.

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, change the 'version' 
to a later Fedora Linux version. Note that the version field may be hidden.
Click the "Show advanced fields" button if you do not see it.

Thank you for reporting this issue and we are sorry that we were not 
able to fix it before Fedora Linux 36 is end of life. If you would still like 
to see this bug fixed and are able to reproduce it against a later version 
of Fedora Linux, you are encouraged to change the 'version' to a later version
prior to this bug being closed.

Comment 8 Ludek Smid 2023-05-25 16:51:51 UTC
Fedora Linux 36 entered end-of-life (EOL) status on 2023-05-16.

Fedora Linux 36 is no longer maintained, which means that it
will not receive any further security or bug fix updates. As a result we
are closing this bug.

If you can reproduce this bug against a currently maintained version of Fedora Linux
please feel free to reopen this bug against that version. Note that the version
field may be hidden. Click the "Show advanced fields" button if you do not see
the version field.

If you are unable to reopen this bug, please file a new report against an
active release.

Thank you for reporting this bug and we are sorry it could not be fixed.


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