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 1913465 - createrepo_c segfault when attempting to print PrimaryXmlFile or PrimarySqlite object after closing
Summary: createrepo_c segfault when attempting to print PrimaryXmlFile or PrimarySqlit...
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 8
Classification: Red Hat
Component: createrepo_c
Version: 8.3
Hardware: x86_64
OS: Linux
low
low
Target Milestone: rc
: 8.0
Assignee: amatej
QA Contact: Jan Blazek
URL:
Whiteboard:
Depends On: 1951406
Blocks:
TreeView+ depends on / blocked
 
Reported: 2021-01-06 20:30 UTC by Ryan Mullett
Modified: 2021-11-09 22:07 UTC (History)
3 users (show)

Fixed In Version: createrepo_c-0.17.2-1.el8
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2021-11-09 18:06:40 UTC
Type: Bug
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)
segfault from RHEL 8 test system illustrating the issue (7.49 MB, application/x-tar)
2021-01-06 20:30 UTC, Ryan Mullett
no flags Details


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2021:4197 0 None None None 2021-11-09 18:06:48 UTC

Description Ryan Mullett 2021-01-06 20:30:00 UTC
Created attachment 1745041 [details]
segfault from RHEL 8 test system illustrating the issue

Description of problem:
After calling the .close() method on a PrimaryXmlFile or PrimarySqlite object, calling __repr__ or __str__ results in a coredump

Version-Release number of selected component (if applicable):
createrepo_c-libs-0.15.11-2.el8.x86_64
python3-createrepo_c-0.15.11-2.el8.x86_64

Issue appears to be present in every release across 7 and 8.

How reproducible:
Always

Steps to Reproduce:
Example 1:
# python3 -c 'import createrepo_c; p = createrepo_c.PrimarySqlite("primary.sqlite"); p.close(); p.__str__()'
Segmentation fault (core dumped)

Example 2:
# python3 -c 'import createrepo_c; p = createrepo_c.PrimarySqlite("primary.sqlite"); p.close(); p.__repr__()'
Segmentation fault (core dumped)

Example 3:
# python3 -c 'import createrepo_c; p = createrepo_c.PrimaryXmlFile("primary.xml"); p.close(); p.__str__()'
Segmentation fault (core dumped)

Example 4:
# python3 -c 'import createrepo_c; p = createrepo_c.PrimaryXmlFile("primary.xml"); p.close(); p.__repr__()'
Segmentation fault (core dumped)

Actual results:
Segfault

Expected results:
After closing, the object should still be available to be read, as is standard for other python modules. For example:

# python -c 'p = open("items.xml"); p.close(); print(p.__str__())'
<_io.TextIOWrapper name='items.xml' mode='r' encoding='UTF-8'>

Additional info:
Looking around it appears that other methods that are fully implemented via this library go through a check to see if the object was already closed. They go through check_XmlFileStatus():

static int
check_XmlFileStatus(const _XmlFileObject *self)
{
    assert(self != NULL);
    assert(XmlFileObject_Check(self));
    if (self->xmlfile == NULL) {
        PyErr_SetString(CrErr_Exception,
            "Improper createrepo_c XmlFile object (Already closed file?).");
        return -1;
    }
    return 0;
}

However, the __repr__ and __str__ do not. This results in a segfault when they try to access the object which is NULL after having been closed.

Comment 1 Ryan Mullett 2021-01-06 20:34:06 UTC
One additional check that was performed, which I neglected to add to initial description is below. This is simply to illustrate that the issue is not the check_XmlFileStatus(). That function is working correctly for other functions which do call it:

# python3 -c 'import createrepo_c; p = createrepo_c.PrimaryXmlFile("backup-primary.xml"); p.close(); p.set_num_of_pkgs(5)'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
createrepo_c.CreaterepoCError: Improper createrepo_c XmlFile object (Already closed file?).

Comment 4 amatej 2021-03-29 14:08:57 UTC
The previous PR was fixing just xmlfile I have made another one which also fixes sqlite and it prints the representation of a closed xmlfile/sqlite instead of throwing an exception.

In addition it adds unit test testing.

https://github.com/rpm-software-management/createrepo_c/pull/257

Comment 22 errata-xmlrpc 2021-11-09 18:06:40 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 (createrepo_c 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-2021:4197


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