Commit b942917
committed
gh-149449: Fix use-after-free in _PyUnicode_GetNameCAPI
The cache stored the raw struct pointer extracted from
unicodedata's _ucnhash_CAPI capsule without keeping a
reference to the owning capsule. Dropping the module from
sys.modules and running gc.collect() then freed the struct
while \N{...} decoding and the namereplace codec handler
were still using it. Hold a strong reference to the
capsule on the interpreter state and Py_CLEAR it in
_PyUnicode_Fini.1 parent fad0674 commit b942917
4 files changed
Lines changed: 62 additions & 4 deletions
File tree
- Include/internal
- Lib/test
- Misc/NEWS.d/next/Core_and_Builtins
- Objects
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
708 | 708 | | |
709 | 709 | | |
710 | 710 | | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
711 | 714 | | |
| 715 | + | |
712 | 716 | | |
713 | 717 | | |
714 | 718 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1106 | 1106 | | |
1107 | 1107 | | |
1108 | 1108 | | |
| 1109 | + | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
| 1119 | + | |
| 1120 | + | |
| 1121 | + | |
| 1122 | + | |
| 1123 | + | |
| 1124 | + | |
1109 | 1125 | | |
1110 | 1126 | | |
1111 | 1127 | | |
| |||
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6445 | 6445 | | |
6446 | 6446 | | |
6447 | 6447 | | |
| 6448 | + | |
| 6449 | + | |
| 6450 | + | |
| 6451 | + | |
| 6452 | + | |
| 6453 | + | |
| 6454 | + | |
| 6455 | + | |
| 6456 | + | |
| 6457 | + | |
| 6458 | + | |
| 6459 | + | |
| 6460 | + | |
| 6461 | + | |
| 6462 | + | |
| 6463 | + | |
| 6464 | + | |
| 6465 | + | |
| 6466 | + | |
| 6467 | + | |
| 6468 | + | |
| 6469 | + | |
6448 | 6470 | | |
6449 | | - | |
6450 | | - | |
| 6471 | + | |
| 6472 | + | |
| 6473 | + | |
6451 | 6474 | | |
6452 | | - | |
| 6475 | + | |
| 6476 | + | |
| 6477 | + | |
| 6478 | + | |
| 6479 | + | |
| 6480 | + | |
6453 | 6481 | | |
6454 | 6482 | | |
| 6483 | + | |
| 6484 | + | |
| 6485 | + | |
6455 | 6486 | | |
6456 | 6487 | | |
6457 | 6488 | | |
| |||
14959 | 14990 | | |
14960 | 14991 | | |
14961 | 14992 | | |
14962 | | - | |
| 14993 | + | |
| 14994 | + | |
| 14995 | + | |
| 14996 | + | |
14963 | 14997 | | |
| 14998 | + | |
14964 | 14999 | | |
14965 | 15000 | | |
14966 | 15001 | | |
| |||
0 commit comments