Bug 800187 - Bugs found in python-yenc-0.3-10.fc17 using gcc-with-cpychecker static analyzer
Bugs found in python-yenc-0.3-10.fc17 using gcc-with-cpychecker static analyzer
Product: Fedora
Classification: Fedora
Component: python-yenc (Show other bugs)
Unspecified Unspecified
unspecified Severity unspecified
: ---
: ---
Assigned To: Conrad Meyer
Fedora Extras Quality Assurance
Depends On:
Blocks: cpychecker
  Show dependency treegraph
Reported: 2012-03-05 17:25 EST by Dave Malcolm
Modified: 2013-04-29 10:48 EDT (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2013-04-29 10:48:06 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description Dave Malcolm 2012-03-05 17:25:08 EST
Description of problem:
I've been writing an experimental static analysis tool to detect bugs commonly occurring within C Python extension modules:

I ran the latest version of the tool (in git master; post 0.9) on
python-yenc-0.3-10.fc17.src.rpm, and it reports various errors.

You can see a list of errors here, triaged into categories (from most significant to least significant):

I've manually reviewed the issues reported by the tool.

Within the category "Unclassified errors" the 1 issue reported is difficult to read (the line numbering seems to be out of sync; the wrong lines are being highlighted), but I think it's complaining about this line:
     172                 encoded++;
which I *think* is a genuine bug: where does "encoded" get initialized?

Within the category "Segfaults within error-handling paths" the 2 issues reported appear to be genuine crashers under low-memory conditions, where the call to PyString_FromStringAndSize could fail, returning NULL:
    Py_output_string = PyString_FromStringAndSize(output_buffer, output_len);
    retval = Py_BuildValue("(S,i,i)", Py_output_string, ...
    Py_DECREF(Py_output_string);  << segfault

It may be easier to instead to use the "s#" format code to Py_BuildValue so that it builds the intermediate string object:
    retval = Py_BuildValue("(s#,i,i)", output_buffer, output_len, ....)
and it correctly performs the necessary error-handling.
(see http://docs.python.org/c-api/arg.html#Py_BuildValue for more information).

There may of course be other bugs in my checker tool.

Hope this is helpful; let me know if you need help reading the logs that the tool generates - I know that it could use some improvement.

Version-Release number of selected component (if applicable):
gcc-python-plugin post-0.9 git 11462291a66c8db693c8884cb84b795bb5988ffb running the checker in an *f16* chroot
Comment 1 Conrad Meyer 2012-03-09 02:33:03 EST
Looks like 'encoded' never gets used anyways, so it doesn't have any opportunity to cause problems. There were some unchecked malloc()s around the Py_BuildValue()s you point out. I'm not sure how much I care about "low-memory conditions" (I think Fedora has overcommit enabled by default) but might as well fix it.
Comment 3 Fedora Update System 2012-03-09 03:22:27 EST
python-yenc-0.3-11.fc16 has been submitted as an update for Fedora 16.
Comment 4 Fedora Update System 2012-03-09 03:22:35 EST
python-yenc-0.3-11.fc17 has been submitted as an update for Fedora 17.
Comment 5 Fedora Update System 2012-03-09 12:58:07 EST
Package python-yenc-0.3-11.fc17:
* should fix your issue,
* was pushed to the Fedora 17 testing repository,
* should be available at your local mirror within two days.
Update it with:
# su -c 'yum update --enablerepo=updates-testing python-yenc-0.3-11.fc17'
as soon as you are able to.
Please go to the following url:
then log in and leave karma (feedback).
Comment 6 Fedora End Of Life 2013-04-03 16:36:42 EDT
This bug appears to have been reported against 'rawhide' during the Fedora 19 development cycle.
Changing version to '19'.

(As we did not run this process for some time, it could affect also pre-Fedora 19 development
cycle bugs. We are very sorry. It will help us with cleanup during Fedora 19 End Of Life. Thank you.)

More information and reason for this action is here:

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