Red Hat Bugzilla – Bug 800187
Bugs found in python-yenc-0.3-10.fc17 using gcc-with-cpychecker static analyzer
Last modified: 2013-04-29 10:48:06 EDT
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:
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
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.
Built in rawhide, f17, f16:
python-yenc-0.3-11.fc16 has been submitted as an update for Fedora 16.
python-yenc-0.3-11.fc17 has been submitted as an update for Fedora 17.
* 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).
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: