]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Fix undefined behaviour in datetime.time.fromisoformat() (#111982)
authorT. Wouters <thomas@python.org>
Sat, 11 Nov 2023 23:56:27 +0000 (00:56 +0100)
committerGitHub <noreply@github.com>
Sat, 11 Nov 2023 23:56:27 +0000 (00:56 +0100)
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).

Modules/_datetimemodule.c

index 9938ed5f8095b575962a7c9774ab6ba63aa2c6e1..cb5403e8461ff0e8972c4e1a515629fe1a11b2f8 100644 (file)
@@ -4630,7 +4630,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);