Skip to content

Commit 2d6f1ff

Browse files
committed
gh-151673: Fix crash in warnings setup_context when filename alloc fails
Check PyUnicode_FromString(\"<sys>\") for NULL before continuing (OOM-0001 / gh-151763).
1 parent f5f5059 commit 2d6f1ff

2 files changed

Lines changed: 4 additions & 0 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix a crash in the warnings module when allocating a synthetic filename fails under memory pressure.

Python/_warnings.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,9 @@ setup_context(Py_ssize_t stack_level,
10351035
globals = interp->sysdict;
10361036
*filename = PyUnicode_FromString("<sys>");
10371037
*lineno = 0;
1038+
if (*filename == NULL) {
1039+
return 0; /* nothing else allocated yet on this path */
1040+
}
10381041
}
10391042
else {
10401043
globals = f->f_frame->f_globals;

0 commit comments

Comments
 (0)