From daca3d7e9b48badf02521df1b729ddd2733b2d77 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Sun, 17 Aug 2014 22:11:06 +0200 Subject: Issue #22206: Using pthread, PyThread_create_key() now sets errno to ENOMEM and returns -1 (error) on integer overflow. --- Misc/NEWS | 3 +++ Python/thread_pthread.h | 10 +++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Misc/NEWS b/Misc/NEWS index 3f7f478..cd4f52b 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,9 @@ Release date: TBA Core and Builtins ----------------- +- Issue #22206: Using pthread, PyThread_create_key() now sets errno to ENOMEM + and returns -1 (error) on integer overflow. + - Issue #20184: Argument Clinic based signature introspection added for 30 of the builtin functions. diff --git a/Python/thread_pthread.h b/Python/thread_pthread.h index d9f7c76..27e0dc8 100644 --- a/Python/thread_pthread.h +++ b/Python/thread_pthread.h @@ -608,7 +608,15 @@ PyThread_create_key(void) { pthread_key_t key; int fail = pthread_key_create(&key, NULL); - return fail ? -1 : key; + if (fail) + return -1; + if (key > INT_MAX) { + /* Issue #22206: handle integer overflow */ + pthread_key_delete(key); + errno = ENOMEM; + return -1; + } + return (int)key; } void -- cgit v0.12