Skip to content

[3.11] gh-116447: Fix possible UB in arraymodule and getargs (GH-116459) #116497

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
merged 1 commit into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Modules/arraymodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ BB_setitem(arrayobject *ap, Py_ssize_t i, PyObject *v)
if (!PyArg_Parse(v, "b;array item must be integer", &x))
return -1;
if (i >= 0)
((char *)ap->ob_item)[i] = x;
((unsigned char *)ap->ob_item)[i] = x;
return 0;
}

Expand Down
4 changes: 2 additions & 2 deletions Python/getargs.c
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
switch (c) {

case 'b': { /* unsigned byte -- very short int */
char *p = va_arg(*p_va, char *);
unsigned char *p = va_arg(*p_va, unsigned char *);
long ival = PyLong_AsLong(arg);
if (ival == -1 && PyErr_Occurred())
RETURN_ERR_OCCURRED;
Expand All @@ -693,7 +693,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,

case 'B': {/* byte sized bitfield - both signed and unsigned
values allowed */
char *p = va_arg(*p_va, char *);
unsigned char *p = va_arg(*p_va, unsigned char *);
unsigned long ival = PyLong_AsUnsignedLongMask(arg);
if (ival == (unsigned long)-1 && PyErr_Occurred())
RETURN_ERR_OCCURRED;
Expand Down