]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.11] Fix undefined behaviour in datetime.time.fromisoformat() (GH-111982) (#111991)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sun, 12 Nov 2023 00:24:02 +0000 (01:24 +0100)
committerGitHub <noreply@github.com>
Sun, 12 Nov 2023 00:24:02 +0000 (00:24 +0000)
Fix undefined behaviour in datetime.time.fromisoformat() (GH-111982)

Fix undefined behaviour in datetime.time.fromisoformat() when parsing a string without a timezone. 'tzoffset' is not assigned to by parse_isoformat_time if it returns 0, but time_fromisoformat then passes tzoffset to another function, which is undefined behaviour (even if the function in question does not use the value).
(cherry picked from commit 21615f77b5a580e83589abae618dbe7c298700e2)

Co-authored-by: T. Wouters <thomas@python.org>
Modules/_datetimemodule.c

index 5c67f38ec2111bc7697e554b02b29f90e56145f2..df0ce722d59af801c85c74831f7a3ab63299f651 100644 (file)
@@ -4649,7 +4649,7 @@ time_fromisoformat(PyObject *cls, PyObject *tstr) {
     }
 
     int hour = 0, minute = 0, second = 0, microsecond = 0;
-    int tzoffset, tzimicrosecond = 0;
+    int tzoffset = 0, tzimicrosecond = 0;
     int rv = parse_isoformat_time(p, len,
                                   &hour, &minute, &second, &microsecond,
                                   &tzoffset, &tzimicrosecond);