Bug 800187

Summary: Bugs found in python-yenc-0.3-10.fc17 using gcc-with-cpychecker static analyzer
Product: [Fedora] Fedora Reporter: Dave Malcolm <dmalcolm>
Component: python-yencAssignee: Conrad Meyer <cse.cem+redhatbugz>
Status: CLOSED ERRATA QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 19CC: cse.cem+redhatbugz
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
URL: http://fedorapeople.org/~dmalcolm/gcc-python-plugin/2012-03-05/python-yenc-0.3-10.fc17/
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2013-04-29 14:48:06 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 789472    

Description Dave Malcolm 2012-03-05 22:25:08 UTC
Description of problem:
I've been writing an experimental static analysis tool to detect bugs commonly occurring within C Python extension modules:
  https://fedorahosted.org/gcc-python-plugin/
  http://gcc-python-plugin.readthedocs.org/en/latest/cpychecker.html
  http://fedoraproject.org/wiki/Features/StaticAnalysisOfPythonRefcounts

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):
http://fedorapeople.org/~dmalcolm/gcc-python-plugin/2012-03-05/python-yenc-0.3-10.fc17/

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):
python-yenc-0.3-10.fc17
gcc-python-plugin post-0.9 git 11462291a66c8db693c8884cb84b795bb5988ffb running the checker in an *f16* chroot

Comment 1 Conrad Meyer 2012-03-09 07:33:03 UTC
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 08:22:27 UTC
python-yenc-0.3-11.fc16 has been submitted as an update for Fedora 16.
https://admin.fedoraproject.org/updates/python-yenc-0.3-11.fc16

Comment 4 Fedora Update System 2012-03-09 08:22:35 UTC
python-yenc-0.3-11.fc17 has been submitted as an update for Fedora 17.
https://admin.fedoraproject.org/updates/python-yenc-0.3-11.fc17

Comment 5 Fedora Update System 2012-03-09 17:58:07 UTC
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:
https://admin.fedoraproject.org/updates/FEDORA-2012-3463/python-yenc-0.3-11.fc17
then log in and leave karma (feedback).

Comment 6 Fedora End Of Life 2013-04-03 20:36:42 UTC
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:
https://fedoraproject.org/wiki/BugZappers/HouseKeeping/Fedora19