From 9dc577a730ae2ff6e06363c9ac36c144b69b98f4 Mon Sep 17 00:00:00 2001 From: Barry Warsaw Date: Wed, 30 Aug 2017 10:35:49 -0400 Subject: [PATCH 1/4] Watch out for NULL return. Found by Kirit Sankar Gupta. --- Python/compile.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Python/compile.c b/Python/compile.c index e547c2fd591c49..c4bb3b8995b9f9 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -3360,6 +3360,10 @@ compiler_subdict(struct compiler *c, expr_ty e, Py_ssize_t begin, Py_ssize_t end } for (i = begin; i < end; i++) { key = get_const_value((expr_ty)asdl_seq_GET(e->v.Dict.keys, i)); + if (key == NULL) { + Py_DECREF(keys); + return 0; + } Py_INCREF(key); PyTuple_SET_ITEM(keys, i - begin, key); } From bc4634d9e4f514ed4dc88cc1300a4bcf7e0cc3a5 Mon Sep 17 00:00:00 2001 From: Barry Warsaw Date: Mon, 4 Sep 2017 09:53:08 -0700 Subject: [PATCH 2/4] Add a blurb entry for the issue. --- .../Core and Builtins/2017-09-04-09-51-53.bpo-31337.CSt-e_.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2017-09-04-09-51-53.bpo-31337.CSt-e_.rst diff --git a/Misc/NEWS.d/next/Core and Builtins/2017-09-04-09-51-53.bpo-31337.CSt-e_.rst b/Misc/NEWS.d/next/Core and Builtins/2017-09-04-09-51-53.bpo-31337.CSt-e_.rst new file mode 100644 index 00000000000000..49976f9ffc00d1 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2017-09-04-09-51-53.bpo-31337.CSt-e_.rst @@ -0,0 +1,2 @@ +Close a minor NULL deference opportunity in compile.c. Found by Kirit +Sankar Gupta. From f7e3c40b2d23d9fd0abab735bee91786a005b35f Mon Sep 17 00:00:00 2001 From: Barry Warsaw Date: Mon, 4 Sep 2017 09:55:19 -0700 Subject: [PATCH 3/4] Typo in blurb entry. --- .../Core and Builtins/2017-09-04-09-51-53.bpo-31337.CSt-e_.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Core and Builtins/2017-09-04-09-51-53.bpo-31337.CSt-e_.rst b/Misc/NEWS.d/next/Core and Builtins/2017-09-04-09-51-53.bpo-31337.CSt-e_.rst index 49976f9ffc00d1..54564b8b3a6e95 100644 --- a/Misc/NEWS.d/next/Core and Builtins/2017-09-04-09-51-53.bpo-31337.CSt-e_.rst +++ b/Misc/NEWS.d/next/Core and Builtins/2017-09-04-09-51-53.bpo-31337.CSt-e_.rst @@ -1,2 +1,2 @@ -Close a minor NULL deference opportunity in compile.c. Found by Kirit +Close a minor NULL dereference opportunity in compile.c. Found by Kirit Sankar Gupta. From 4600bcf9cd356a7e9364809f5583375592b0ba63 Mon Sep 17 00:00:00 2001 From: Barry Warsaw Date: Mon, 4 Sep 2017 14:58:34 -0700 Subject: [PATCH 4/4] Set an appropriate exception. --- Python/compile.c | 1 + 1 file changed, 1 insertion(+) diff --git a/Python/compile.c b/Python/compile.c index c4bb3b8995b9f9..c6f5333c64ad27 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -3362,6 +3362,7 @@ compiler_subdict(struct compiler *c, expr_ty e, Py_ssize_t begin, Py_ssize_t end key = get_const_value((expr_ty)asdl_seq_GET(e->v.Dict.keys, i)); if (key == NULL) { Py_DECREF(keys); + PyErr_BadInternalCall(); return 0; } Py_INCREF(key);