Skip to content

Commit fdb2d90

Browse files
authored
gh-116447: Fix possible UB in arraymodule and getargs (#116459)
1 parent 0003285 commit fdb2d90

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

Modules/arraymodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ BB_setitem(arrayobject *ap, Py_ssize_t i, PyObject *v)
247247
if (!PyArg_Parse(v, "b;array item must be integer", &x))
248248
return -1;
249249
if (i >= 0)
250-
((char *)ap->ob_item)[i] = x;
250+
((unsigned char *)ap->ob_item)[i] = x;
251251
return 0;
252252
}
253253

Python/getargs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
612612
switch (c) {
613613

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

634634
case 'B': {/* byte sized bitfield - both signed and unsigned
635635
values allowed */
636-
char *p = va_arg(*p_va, char *);
636+
unsigned char *p = va_arg(*p_va, unsigned char *);
637637
unsigned long ival = PyLong_AsUnsignedLongMask(arg);
638638
if (ival == (unsigned long)-1 && PyErr_Occurred())
639639
RETURN_ERR_OCCURRED;

0 commit comments

Comments
 (0)