]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.11] gh-116447: Fix possible UB in `arraymodule` and `getargs` (GH-116459) (#116497)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Fri, 8 Mar 2024 11:25:39 +0000 (12:25 +0100)
committerGitHub <noreply@github.com>
Fri, 8 Mar 2024 11:25:39 +0000 (11:25 +0000)
gh-116447: Fix possible UB in `arraymodule` and `getargs` (GH-116459)
(cherry picked from commit fdb2d90a274158aee23b526d972172bf41bd4b7e)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Modules/arraymodule.c
Python/getargs.c

index 312ab92eb7123203f9c3e3f0102b299214aa38d8..7699b1910b57affeae6eff9271928491cf018f1a 100644 (file)
@@ -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;
 }
 
index e18d77199291612889bee7c79ff8f1a2b1090d7f..b6651aee60c0f25b448b0cd388f992921361cad2 100644 (file)
@@ -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;
@@ -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;