https://github.com/python/cpython/commit/fdb2d90a274158aee23b526d972172bf41bd4b7e
commit: fdb2d90a274158aee23b526d972172bf41bd4b7e
branch: main
author: Nikita Sobolev <[email protected]>
committer: sobolevn <[email protected]>
date: 2024-03-08T13:49:52+03:00
summary:

gh-116447: Fix possible UB in `arraymodule` and `getargs` (#116459)

files:
M Modules/arraymodule.c
M Python/getargs.c

diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c
index df09d9d84789f7..317f4974814945 100644
--- a/Modules/arraymodule.c
+++ b/Modules/arraymodule.c
@@ -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;
 }
 
diff --git a/Python/getargs.c b/Python/getargs.c
index 08e97ee3e627b5..bec981698767ca 100644
--- a/Python/getargs.c
+++ b/Python/getargs.c
@@ -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;
@@ -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;

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to