Skip to content

Commit d1fcdf2

Browse files
committed
gh-155454: Fix platform.libc_ver() crash on threaded libc without version
A libc.so match with a thread suffix but no version left ver as None, which was then subscripted. Guard the check with ver is not None.
1 parent 7c653e2 commit d1fcdf2

3 files changed

Lines changed: 6 additions & 1 deletion

File tree

Lib/platform.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,8 @@ def libc_ver(executable=None, lib='', version='', chunksize=16384):
240240
lib = 'libc'
241241
if soversion and (not ver or V(soversion) > V(ver)):
242242
ver = soversion
243-
if threads and ver[-len(threads):] != threads:
243+
if (threads and ver is not None
244+
and ver[-len(threads):] != threads):
244245
ver = ver + threads
245246
elif musl:
246247
lib = 'musl'

Lib/test/test_platform.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,7 @@ def test_libc_ver(self):
576576
(b'GLIBC_2.9', ('glibc', '2.9')),
577577
(b'libc.so.1.2.5', ('libc', '1.2.5')),
578578
(b'libc_pthread.so.1.2.5', ('libc', '1.2.5_pthread')),
579+
(b'libc_r.so', ('libc', '')),
579580
(b'/aports/main/musl/src/musl-1.2.5', ('musl', '1.2.5')),
580581
# musl uses semver, but we accept some variations anyway:
581582
(b'/aports/main/musl/src/musl-12.5', ('musl', '12.5')),
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix :func:`platform.libc_ver` crashing with :exc:`TypeError` when the scanned
2+
binary references a threaded C library (such as ``libc_r``) that has no version
3+
number. Patch by tonghuaroot.

0 commit comments

Comments
 (0)