]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-40998: Address compiler warnings found by ubsan (GH-20929)
authorChristian Heimes <christian@python.org>
Wed, 18 Nov 2020 15:38:53 +0000 (16:38 +0100)
committerGitHub <noreply@github.com>
Wed, 18 Nov 2020 15:38:53 +0000 (07:38 -0800)
Signed-off-by: Christian Heimes <christian@python.org>
Automerge-Triggered-By: GH:tiran
Misc/NEWS.d/next/Build/2020-06-17-09-05-02.bpo-40998.sgqmg9.rst [new file with mode: 0644]
Objects/unicodeobject.c
Parser/string_parser.c
Python/pylifecycle.c

diff --git a/Misc/NEWS.d/next/Build/2020-06-17-09-05-02.bpo-40998.sgqmg9.rst b/Misc/NEWS.d/next/Build/2020-06-17-09-05-02.bpo-40998.sgqmg9.rst
new file mode 100644 (file)
index 0000000..c268e4f
--- /dev/null
@@ -0,0 +1,2 @@
+Addressed three compiler warnings found by undefined behavior sanitizer
+(ubsan).
index e7a63e7b973d89ce42ded1858c116bdbccca2711..70688c8c013816f6d779243762f37bd3db2b7045 100644 (file)
@@ -839,7 +839,11 @@ xmlcharrefreplace(_PyBytesWriter *writer, char *str,
 
     /* generate replacement */
     for (i = collstart; i < collend; ++i) {
-        str += sprintf(str, "&#%d;", PyUnicode_READ(kind, data, i));
+        size = sprintf(str, "&#%d;", PyUnicode_READ(kind, data, i));
+        if (size < 0) {
+            return NULL;
+        }
+        str += size;
     }
     return str;
 }
index 1285968b31917735c17c290c62bddd4176a700e1..8f6433dbcec1313745b6b0a52ee25d9dc5f499d3 100644 (file)
@@ -69,6 +69,9 @@ decode_unicode_with_escapes(Parser *parser, const char *s, size_t len, Token *t)
         return NULL;
     }
     p = buf = PyBytes_AsString(u);
+    if (p == NULL) {
+        return NULL;
+    }
     end = s + len;
     while (s < end) {
         if (*s == '\\') {
index 82ce4f15ad283af95402641300a6ca3bec27ee81..9771951d2d84caf6b2364f83ac9b300152901616 100644 (file)
@@ -1644,7 +1644,6 @@ Py_FinalizeEx(void)
 
     /* Get current thread state and interpreter pointer */
     PyThreadState *tstate = _PyRuntimeState_GetThreadState(runtime);
-    PyInterpreterState *interp = tstate->interp;
 
     // Wrap up existing "threading"-module-created, non-daemon threads.
     wait_for_thread_shutdown(tstate);
@@ -1667,13 +1666,13 @@ Py_FinalizeEx(void)
     /* Copy the core config, PyInterpreterState_Delete() free
        the core config memory */
 #ifdef Py_REF_DEBUG
-    int show_ref_count = interp->config.show_ref_count;
+    int show_ref_count = tstate->interp->config.show_ref_count;
 #endif
 #ifdef Py_TRACE_REFS
-    int dump_refs = interp->config.dump_refs;
+    int dump_refs = tstate->interp->config.dump_refs;
 #endif
 #ifdef WITH_PYMALLOC
-    int malloc_stats = interp->config.malloc_stats;
+    int malloc_stats = tstate->interp->config.malloc_stats;
 #endif
 
     /* Remaining daemon threads will automatically exit