From 1f6dc6bddba1a3e3ed49b43ed83c27b069a4a1a3 Mon Sep 17 00:00:00 2001 From: Honglin Zhu Date: Thu, 28 Jul 2022 13:13:48 +0800 Subject: [PATCH 1/3] gh-95355: Check tokens[0] after allocating memory --- Parser/pegen.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Parser/pegen.c b/Parser/pegen.c index dbf105aedcf427..31e3ec05a10530 100644 --- a/Parser/pegen.c +++ b/Parser/pegen.c @@ -738,7 +738,7 @@ _PyPegen_Parser_New(struct tok_state *tok, int start_rule, int flags, return (Parser *) PyErr_NoMemory(); } p->tokens[0] = PyMem_Calloc(1, sizeof(Token)); - if (!p->tokens) { + if (!p->tokens[0]) { PyMem_Free(p->tokens); PyMem_Free(p); return (Parser *) PyErr_NoMemory(); From 2f1c0fe7ff4fcf5335dfa71ec74a759582fd76fc Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Thu, 28 Jul 2022 08:33:32 +0000 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../2022-07-28-08-33-31.gh-issue-95355.yN4XVk.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2022-07-28-08-33-31.gh-issue-95355.yN4XVk.rst diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-07-28-08-33-31.gh-issue-95355.yN4XVk.rst b/Misc/NEWS.d/next/Core and Builtins/2022-07-28-08-33-31.gh-issue-95355.yN4XVk.rst new file mode 100644 index 00000000000000..c7db73880f6f21 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2022-07-28-08-33-31.gh-issue-95355.yN4XVk.rst @@ -0,0 +1 @@ +Check tokens[0] after allocating memory From 58821f2486070ad6feb9470aab4890cc3f9db9b6 Mon Sep 17 00:00:00 2001 From: Honglin Zhu Date: Thu, 28 Jul 2022 17:23:09 +0800 Subject: [PATCH 3/3] Update Misc/NEWS.d/next/Core and Builtins/2022-07-28-08-33-31.gh-issue-95355.yN4XVk.rst Co-authored-by: Oleg Iarygin --- .../2022-07-28-08-33-31.gh-issue-95355.yN4XVk.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-07-28-08-33-31.gh-issue-95355.yN4XVk.rst b/Misc/NEWS.d/next/Core and Builtins/2022-07-28-08-33-31.gh-issue-95355.yN4XVk.rst index c7db73880f6f21..6a289991e0d60f 100644 --- a/Misc/NEWS.d/next/Core and Builtins/2022-07-28-08-33-31.gh-issue-95355.yN4XVk.rst +++ b/Misc/NEWS.d/next/Core and Builtins/2022-07-28-08-33-31.gh-issue-95355.yN4XVk.rst @@ -1 +1 @@ -Check tokens[0] after allocating memory +``_PyPegen_Parser_New`` now properly detects token memory allocation errors. Patch by Honglin Zhu.