Skip to content

Commit

Permalink
pythongh-116447: Fix possible UB in arraymodule and getargs (pyth…
Browse files Browse the repository at this point in the history
  • Loading branch information
sobolevn authored Mar 8, 2024
1 parent 0003285 commit fdb2d90
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Modules/arraymodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,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 @@ -612,7 +612,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 @@ -633,7 +633,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

0 comments on commit fdb2d90

Please sign in to comment.