- Python Home
- About
- News
- Documentation
- Downloads
- Community
- Foundation
- Developer's Guide
- Issue Tracker
- Issues
- Summaries
- User
- Administration
- Help
➜
This issue tracker has been migrated to GitHub,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
| Author | Oren Milman |
|---|---|
| Recipients | Oren Milman |
| Date | 2017-09-25.10:58:17 |
| SpamBayes Score | -1.0 |
| Marked as misclassified | Yes |
| Message-id | <1506337097.58.0.681670010247.issue31573@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
|---|
The following code causes the interpreter to crash:
import os
import time
import resource
new_pid = os.fork()
if new_pid == 0:
time.sleep(0.5)
else:
resource.struct_rusage = None
os.wait3(0)
We would get a crash also if we replaced 'os.wait3(0)' with 'os.wait4(new_pid, 0)'.
This is because wait_helper() (in in Modules/posixmodule.c) assumes that
resource.struct_rusage is a type object, and passes it to PyStructSequence_New(),
which tries to access the n_fields attribute, and crashes.
In addition, the following code causes a SystemError:
class BadStructRusage:
n_fields = None
import os
import time
import resource
new_pid = os.fork()
if new_pid == 0:
time.sleep(0.5)
else:
resource.struct_rusage = BadStructRusage
os.wait3(0)
This is because PyStructSequence_New() (in Objects/structseq.c) assumes that it
received a type with a valid n_fields attribute.
Similarly, the following code causes the interpreter to crash:
class BadStructRusage:
n_fields = 16
n_sequence_fields = None
import os
import time
import resource
new_pid = os.fork()
if new_pid == 0:
time.sleep(0.5)
else:
resource.struct_rusage = BadStructRusage
os.wait3(0)
ISTM that we can fix these problems by adding checks to wait_helper() and to
PyStructSequence_New().
However, maybe a more simple solution would be to either:
- Make wait_helper() always use StructRUsageType (defined in Modules/resource.c).
- Disable assigning to resource.struct_rusage.
Moreover, I don't understand the comment before calling PyStructSequence_New():
/* XXX(nnorwitz): Copied (w/mods) from resource.c, there should be only one. */
Is it relevant to this issue?
Lastly, I am not sure about tests (as I found almost no tests of wait3() and
wait4()).
Should I add to Lib/test/test_wait3.py and Lib/test/test_wait4.py each a class
to test this issue? Or is it too much of a corner case, and a test is not needed? |
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2017-09-25 10:58:17 | Oren Milman | set | recipients: + Oren Milman |
| 2017-09-25 10:58:17 | Oren Milman | set | messageid: <1506337097.58.0.681670010247.issue31573@psf.upfronthosting.co.za> |
| 2017-09-25 10:58:17 | Oren Milman | link | issue31573 messages |
| 2017-09-25 10:58:17 | Oren Milman | create |
Powered by Roundup Copyright © 1990-2022, Python Software Foundation
Legal Statements
