Movatterモバイル変換


[0]ホーム

URL:


homepage

Issue22206

This issue trackerhas been migrated toGitHub, and is currentlyread-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title:PyThread_create_key(): fix comparison between signed and unsigned numbers in Python/thread_pthread.h
Type:behaviorStage:patch review
Components:Versions:Python 3.5
process
Status:closedResolution:fixed
Dependencies:Superseder:
Assigned To:Nosy List: neologix, pitrou, python-dev, vstinner
Priority:normalKeywords:patch

Created on2014-08-15 21:45 byvstinner, last changed2022-04-11 14:58 byadmin. This issue is nowclosed.

Files
File nameUploadedDescriptionEdit
PyThread_create_key.patchvstinner,2014-08-15 21:45review
pthread_key_create_overflow.patchvstinner,2014-08-16 12:08review
Messages (4)
msg225367 -(view)Author: STINNER Victor (vstinner)*(Python committer)Date: 2014-08-15 21:45
The issue#22110 enabled more compiler warnings. I would like to fix this one:---gcc -pthread -c -Wno-unused-result -Wsign-compare -g -O0 -Wall -Wstrict-prototypes    -Werror=declaration-after-statement   -I. -IInclude -I./Include    -DPy_BUILD_CORE -oPython/thread.oPython/thread.cIn file included fromPython/thread.c:86:0:Python/thread_pthread.h: In function ‘PyThread_create_key’:Python/thread_pthread.h:611:22: attention : signed and unsigned type in conditional expression [-Wsign-compare]     return fail ? -1 : key;                      ^---Attached patch uses Py_SAFE_DOWNCAST() to explicitly downcast to int.On Linux (on my Fedora 20/amd64), pthread_key_t is defined as an unsigned int, whereas the result type of PyThread_create_key is a signed int.Nobody complained before, so I get that nobody noticed the possible overflow for a key > INT_MAX. I checked the code, we only check if PyThread_create_key() returns -1, if you reach UINT_MAX keys. UINT_MAX keys sounds insane, you probably hit another limit before.On Linux, it looks like the key is a counter and deleted values are reused:haypo@selma$ ./pythonPython 3.5.0a0 (default:a0b38f4eb79e, Aug 15 2014, 23:37:42) [GCC 4.8.3 20140624 (Red Hat 4.8.3-1)] on linuxType "help", "copyright", "credits" or "license" for more information.>>> import ctypes>>> ctypes.pythonapi.PyThread_create_key()2>>> ctypes.pythonapi.PyThread_create_key()3>>> ctypes.pythonapi.PyThread_create_key()4>>> ctypes.pythonapi.PyThread_delete_key(3)0>>> ctypes.pythonapi.PyThread_create_key()3
msg225390 -(view)Author: STINNER Victor (vstinner)*(Python committer)Date: 2014-08-16 12:08
pthread_key_create_overflow.patch: safer patch, delete the newly created key and return an error on integer overflow.
msg225467 -(view)Author: Roundup Robot (python-dev)(Python triager)Date: 2014-08-17 20:14
New changeset1b898b5d5ffe by Victor Stinner in branch 'default':Issue#22206: Using pthread, PyThread_create_key() now sets errno to ENOMEM andhttp://hg.python.org/cpython/rev/1b898b5d5ffe
msg225468 -(view)Author: STINNER Victor (vstinner)*(Python committer)Date: 2014-08-17 20:15
I fixed the issue in Python 3.5, I close the issue.Even if Python 2.7 and 3.4 are also affected, I prefer to not modify them to not take the risk of introducing a regression for a corner case.
History
DateUserActionArgs
2022-04-11 14:58:07adminsetgithub: 66402
2014-08-17 20:15:23vstinnersetstatus: open -> closed
resolution: fixed
messages: +msg225468

versions: - Python 2.7, Python 3.4
2014-08-17 20:14:05python-devsetnosy: +python-dev
messages: +msg225467
2014-08-16 12:58:51serhiy.storchakasetnosy: +pitrou
stage: patch review
type: behavior

versions: + Python 2.7, Python 3.4
2014-08-16 12:08:16vstinnersetfiles: +pthread_key_create_overflow.patch

messages: +msg225390
2014-08-15 21:46:12vstinnersettitle: PyThread_create_key(): fix comparison between signed and unsigned numbers -> PyThread_create_key(): fix comparison between signed and unsigned numbers in Python/thread_pthread.h
2014-08-15 21:45:30vstinnercreate
Supported byThe Python Software Foundation,
Powered byRoundup
Copyright © 1990-2022,Python Software Foundation
Legal Statements

[8]ページ先頭

©2009-2026 Movatter.jp