-
- Notifications
You must be signed in to change notification settings - Fork 33.5k
bpo-30058: Fixed buffer overflow in select.kqueue.control(). #1095
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
serhiy-storchaka merged 9 commits into python:master from serhiy-storchaka:kqueue-control-buffer-overflow Oct 12, 2017
Merged
Changes from 1 commit
Commits
Show all changes
9 commits Select commit Hold shift + click to select a range
fe41d62 bpo-30058: Fixed buffer overflow in select.kqueue.control().
serhiy-storchaka 4a4a800 Check nchanges for overflow.
serhiy-storchaka 4a3e547 Fix typo and overflow checking.
serhiy-storchaka 1741e09 Fix a typo.
serhiy-storchaka 6b180ca Merge branch 'master' into kqueue-control-buffer-overflow
serhiy-storchaka bc37605 Move a NEWS entry to NEWS.d/.
serhiy-storchaka 535118d Merge branch 'master' into kqueue-control-buffer-overflow
serhiy-storchaka 8168c08 Merge branch 'master' into kqueue-control-buffer-overflow
serhiy-storchaka 30be553 Fixed errors and clean up the code.
serhiy-storchaka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| | @@ -2102,7 +2102,7 @@ kqueue_queue_control(kqueue_queue_Object *self, PyObject *args) | |
| int i = 0; | ||
| PyObject *otimeout = NULL; | ||
| PyObject *ch = NULL; | ||
| PyObject *it = NULL, *ei = NULL; | ||
| PyObject *seq = NULL, *ei = NULL; | ||
| PyObject *result = NULL; | ||
| struct kevent *evl = NULL; | ||
| struct kevent *chl = NULL; | ||
| | @@ -2148,37 +2148,31 @@ kqueue_queue_control(kqueue_queue_Object *self, PyObject *args) | |
| } | ||
| | ||
| if (ch != NULL && ch != Py_None) { | ||
| it = PyObject_GetIter(ch); | ||
| if (it == NULL) { | ||
| PyErr_SetString(PyExc_TypeError, | ||
| "changelist is not iterable"); | ||
| seq = PySequence_Fast(ch, "changelist is not iterable"); | ||
| if (seq == NULL) { | ||
| return NULL; | ||
| } | ||
| nchanges = PyObject_Size(ch); | ||
| if (nchanges < 0) { | ||
| goto error; | ||
| } | ||
| nchanges = PySequence_Fast_GET_SIZE(arg); | ||
| ||
| | ||
| chl = PyMem_New(struct kevent, nchanges); | ||
| if (chl == NULL) { | ||
| PyErr_NoMemory(); | ||
| goto error; | ||
| } | ||
| i = 0; | ||
| while ((ei = PyIter_Next(it)) != NULL) { | ||
| for (i = 0; i < nchanges; ++i) { | ||
| ei = PySequence_Fast_GET_ITEM(seq, i); | ||
| if (!kqueue_event_Check(ei)) { | ||
| Py_DECREF(ei); | ||
| PyErr_SetString(PyExc_TypeError, | ||
| "changelist must be an iterable of " | ||
| "select.kevent objects"); | ||
| goto error; | ||
| } else { | ||
| chl[i++] = ((kqueue_event_Object *)ei)->e; | ||
| } | ||
| Py_DECREF(ei); | ||
| } | ||
| } | ||
| Py_CLEAR(it); | ||
| Py_CLEAR(seq); | ||
| | ||
| /* event list */ | ||
| if (nevents) { | ||
| | @@ -2246,15 +2240,15 @@ kqueue_queue_control(kqueue_queue_Object *self, PyObject *args) | |
| PyMem_Free(chl); | ||
| PyMem_Free(evl); | ||
| Py_XDECREF(result); | ||
| Py_XDECREF(it); | ||
| Py_XDECREF(seq); | ||
| return NULL; | ||
| } | ||
| | ||
| PyDoc_STRVAR(kqueue_queue_control_doc, | ||
| "control(changelist, max_events[, timeout=None]) -> eventlist\n\ | ||
| \n\ | ||
| Calls the kernel kevent function.\n\ | ||
| - changelist must be a list of kevent objects describing the changes\n\ | ||
| - changelist must be an iterable of kevent objects describing the changes\n\ | ||
| to be made to the kernel's watch list or None.\n\ | ||
| - max_events lets you specify the maximum number of events that the\n\ | ||
| kernel will return.\n\ | ||
| | ||
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo:
chagelist->changelistThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch @lulouie!