This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: PyOS_mystricmp advances pointers too far
Type: behavior Stage: resolved
Components: C API Versions: Python 3.10, Python 3.9, Python 3.8, Python 3.7, Python 3.6, Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: corona10, miss-islington, serhiy.storchaka, wmeehan
Priority: normal Keywords: easy (C), patch

Created on 2020-08-11 22:01 by wmeehan, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 21845 merged wmeehan, 2020-08-12 17:06
PR 21978 merged miss-islington, 2020-08-27 05:46
PR 21979 closed miss-islington, 2020-08-27 05:46
PR 22016 merged miss-islington, 2020-08-30 06:54
Messages (6)
msg375203 - (view) Author: William Meehan (wmeehan) * Date: 2020-08-11 22:01
The existing implementation of PyOS_mystricmp increments both pointers as long as the first string hasn't reached the end yet. If the second string ends first, then we increment past the null byte. If there is a difference in the middle of the two strings, then the result actually compares the following pair of letters.

e.g.
PyOS_mystricmp("a", "\0") => 0 (should be positive)
PyOS_mystricmp("foo", "fro") => 0 (should be negative)

Similarly, PyOS_mystrnicmp increments the pointers in a condition before breaking out of the loop. It's possible to increment the first pointer without incrementing the second, and the result is the character past the null byte.

e.g.
PyOS_mystrnicmp("\0a", "\0b", 2) => 97 (should be negative)
msg375208 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2020-08-12 04:46
Good catch! Do you mind to provide a PR for this William?
msg375982 - (view) Author: Dong-hee Na (corona10) * (Python committer) Date: 2020-08-27 05:45
New changeset 97eaf2b5e5c826b9abe59896a363853bef55c5d9 by wmeehan in branch 'master':
bpo-41524: fix pointer bug in PyOS_mystr{n}icmp (GH-21845)
https://github.com/python/cpython/commit/97eaf2b5e5c826b9abe59896a363853bef55c5d9
msg376101 - (view) Author: Dong-hee Na (corona10) * (Python committer) Date: 2020-08-30 06:53
New changeset 901c2eae6e27ee7793e5a3c638664e01a3bf8de8 by Miss Islington (bot) in branch '3.9':
bpo-41524: fix pointer bug in PyOS_mystr{n}icmp (GH-21845) (GH-21978)
https://github.com/python/cpython/commit/901c2eae6e27ee7793e5a3c638664e01a3bf8de8
msg376102 - (view) Author: Dong-hee Na (corona10) * (Python committer) Date: 2020-08-30 07:20
New changeset 85ca9c049c5a490d143d28933bbb02ab80394ed8 by Miss Islington (bot) in branch '3.8':
bpo-41524: fix pointer bug in PyOS_mystr{n}icmp (GH-21845) (GH-22016)
https://github.com/python/cpython/commit/85ca9c049c5a490d143d28933bbb02ab80394ed8
msg376103 - (view) Author: Dong-hee Na (corona10) * (Python committer) Date: 2020-08-30 07:21
Thanks William
History
Date User Action Args
2022-04-11 14:59:34adminsetgithub: 85696
2021-08-09 19:14:17iritkatriellinkissue22330 superseder
2020-08-30 07:21:09corona10setstatus: open -> closed
resolution: fixed
messages: + msg376103

stage: patch review -> resolved
2020-08-30 07:20:43corona10setmessages: + msg376102
2020-08-30 06:54:02miss-islingtonsetpull_requests: + pull_request21116
2020-08-30 06:53:16corona10setmessages: + msg376101
2020-08-27 05:46:38miss-islingtonsetpull_requests: + pull_request21088
2020-08-27 05:46:30miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request21087
2020-08-27 05:45:58corona10setnosy: + corona10
messages: + msg375982
2020-08-12 17:06:04wmeehansetkeywords: + patch
stage: needs patch -> patch review
pull_requests: + pull_request20972
2020-08-12 04:46:04serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg375208

keywords: + easy (C)
stage: needs patch
2020-08-11 22:01:38wmeehancreate