aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/patches/fix-msan-for-pydantic-2.patch
blob: c6893ffe3cf4401da425c7186ea72bfdd408ef93 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
commit c6da6f130038532c120beefe89fcbab987434d66
author: serjflint
committer: shadchin
date: 2023-12-29T07:22:46+03:00

    fix msan

--- contrib/tools/python3/Objects/capsule.c	(66e7c1ee23780a1434d1b4140c654a63ccd65503)
+++ contrib/tools/python3/Objects/capsule.c	(c6da6f130038532c120beefe89fcbab987434d66)
@@ -197,6 +197,11 @@ PyCapsule_Import(const char *name, int no_block)
     PyObject *object = NULL;
     void *return_value = NULL;
     char *trace;
+#if defined(__has_feature)
+#  if __has_feature(memory_sanitizer)
+    __msan_unpoison_string(name);
+#  endif
+#endif
     size_t name_length = (strlen(name) + 1) * sizeof(char);
     char *name_dup = (char *)PyMem_Malloc(name_length);
 
--- contrib/tools/python3/Objects/typeobject.c	(66e7c1ee23780a1434d1b4140c654a63ccd65503)
+++ contrib/tools/python3/Objects/typeobject.c	(c6da6f130038532c120beefe89fcbab987434d66)
@@ -4140,6 +4140,11 @@ _PyType_FromMetaclass_impl(
                 tp_doc = NULL;
             }
             else {
+#if defined(__has_feature)
+#  if __has_feature(memory_sanitizer)
+                __msan_unpoison_string(slot->pfunc);
+#  endif
+#endif
                 size_t len = strlen(slot->pfunc)+1;
                 tp_doc = PyObject_Malloc(len);
                 if (tp_doc == NULL) {
@@ -4160,6 +4165,12 @@ _PyType_FromMetaclass_impl(
         goto finally;
     }
 
+
+#if defined(__has_feature)
+#  if __has_feature(memory_sanitizer)
+    __msan_unpoison_string(spec->name);
+#  endif
+#endif
     const char *s = strrchr(spec->name, '.');
     if (s == NULL) {
         s = spec->name;
--- contrib/tools/python3/Objects/unicodeobject.c	(66e7c1ee23780a1434d1b4140c654a63ccd65503)
+++ contrib/tools/python3/Objects/unicodeobject.c	(c6da6f130038532c120beefe89fcbab987434d66)
@@ -2269,6 +2269,11 @@ PyUnicode_FromStringAndSize(const char *u, Py_ssize_t size)
 PyObject *
 PyUnicode_FromString(const char *u)
 {
+#if defined(__has_feature)
+#  if __has_feature(memory_sanitizer)
+    __msan_unpoison_string(u);
+#  endif
+#endif
     size_t size = strlen(u);
     if (size > PY_SSIZE_T_MAX) {
         PyErr_SetString(PyExc_OverflowError, "input too long");
--- contrib/tools/python3/Parser/tokenizer.c        (index)
+++ contrib/tools/python3/Parser/tokenizer.c        (working tree)
@@ -823,6 +823,11 @@ static char *
 static char *translate_newlines(const char *s, int exec_input,
                                 int preserve_crlf, struct tok_state *tok) {
   int skip_next_lf = 0;
+#if defined(__has_feature)
+#  if __has_feature(memory_sanitizer)
+    __msan_unpoison_string(s);
+#  endif
+#endif
   size_t needed_length = strlen(s) + 2, final_length;
   char *buf, *current;
   char c = '\0';
--- contrib/tools/python3/Python/errors.c	(66e7c1ee23780a1434d1b4140c654a63ccd65503)
+++ contrib/tools/python3/Python/errors.c	(c6da6f130038532c120beefe89fcbab987434d66)
@@ -1161,6 +1161,11 @@ PyErr_NewException(const char *name, PyObject *base, PyObject *dict)
     PyObject *bases = NULL;
     PyObject *result = NULL;
 
+#if defined(__has_feature)
+#  if __has_feature(memory_sanitizer)
+    __msan_unpoison_string(name);
+#  endif
+#endif
     const char *dot = strrchr(name, '.');
     if (dot == NULL) {
         _PyErr_SetString(tstate, PyExc_SystemError,