fix-msan-for-pydantic-2.patch 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. commit c6da6f130038532c120beefe89fcbab987434d66
  2. author: serjflint
  3. committer: shadchin
  4. date: 2023-12-29T07:22:46+03:00
  5. fix msan
  6. --- contrib/tools/python3/Objects/capsule.c (66e7c1ee23780a1434d1b4140c654a63ccd65503)
  7. +++ contrib/tools/python3/Objects/capsule.c (c6da6f130038532c120beefe89fcbab987434d66)
  8. @@ -197,6 +197,11 @@ PyCapsule_Import(const char *name, int no_block)
  9. PyObject *object = NULL;
  10. void *return_value = NULL;
  11. char *trace;
  12. +#if defined(__has_feature)
  13. +# if __has_feature(memory_sanitizer)
  14. + __msan_unpoison_string(name);
  15. +# endif
  16. +#endif
  17. size_t name_length = (strlen(name) + 1) * sizeof(char);
  18. char *name_dup = (char *)PyMem_Malloc(name_length);
  19. --- contrib/tools/python3/Objects/typeobject.c (66e7c1ee23780a1434d1b4140c654a63ccd65503)
  20. +++ contrib/tools/python3/Objects/typeobject.c (c6da6f130038532c120beefe89fcbab987434d66)
  21. @@ -4140,6 +4140,11 @@ _PyType_FromMetaclass_impl(
  22. tp_doc = NULL;
  23. }
  24. else {
  25. +#if defined(__has_feature)
  26. +# if __has_feature(memory_sanitizer)
  27. + __msan_unpoison_string(slot->pfunc);
  28. +# endif
  29. +#endif
  30. size_t len = strlen(slot->pfunc)+1;
  31. tp_doc = PyObject_Malloc(len);
  32. if (tp_doc == NULL) {
  33. @@ -4160,6 +4165,12 @@ _PyType_FromMetaclass_impl(
  34. goto finally;
  35. }
  36. +
  37. +#if defined(__has_feature)
  38. +# if __has_feature(memory_sanitizer)
  39. + __msan_unpoison_string(spec->name);
  40. +# endif
  41. +#endif
  42. const char *s = strrchr(spec->name, '.');
  43. if (s == NULL) {
  44. s = spec->name;
  45. --- contrib/tools/python3/Objects/unicodeobject.c (66e7c1ee23780a1434d1b4140c654a63ccd65503)
  46. +++ contrib/tools/python3/Objects/unicodeobject.c (c6da6f130038532c120beefe89fcbab987434d66)
  47. @@ -2269,6 +2269,11 @@ PyUnicode_FromStringAndSize(const char *u, Py_ssize_t size)
  48. PyObject *
  49. PyUnicode_FromString(const char *u)
  50. {
  51. +#if defined(__has_feature)
  52. +# if __has_feature(memory_sanitizer)
  53. + __msan_unpoison_string(u);
  54. +# endif
  55. +#endif
  56. size_t size = strlen(u);
  57. if (size > PY_SSIZE_T_MAX) {
  58. PyErr_SetString(PyExc_OverflowError, "input too long");
  59. --- contrib/tools/python3/Parser/tokenizer.c (index)
  60. +++ contrib/tools/python3/Parser/tokenizer.c (working tree)
  61. @@ -823,6 +823,11 @@ static char *
  62. static char *translate_newlines(const char *s, int exec_input,
  63. int preserve_crlf, struct tok_state *tok) {
  64. int skip_next_lf = 0;
  65. +#if defined(__has_feature)
  66. +# if __has_feature(memory_sanitizer)
  67. + __msan_unpoison_string(s);
  68. +# endif
  69. +#endif
  70. size_t needed_length = strlen(s) + 2, final_length;
  71. char *buf, *current;
  72. char c = '\0';
  73. --- contrib/tools/python3/Python/errors.c (66e7c1ee23780a1434d1b4140c654a63ccd65503)
  74. +++ contrib/tools/python3/Python/errors.c (c6da6f130038532c120beefe89fcbab987434d66)
  75. @@ -1161,6 +1161,11 @@ PyErr_NewException(const char *name, PyObject *base, PyObject *dict)
  76. PyObject *bases = NULL;
  77. PyObject *result = NULL;
  78. +#if defined(__has_feature)
  79. +# if __has_feature(memory_sanitizer)
  80. + __msan_unpoison_string(name);
  81. +# endif
  82. +#endif
  83. const char *dot = strrchr(name, '.');
  84. if (dot == NULL) {
  85. _PyErr_SetString(tstate, PyExc_SystemError,