From: T. Wouters Date: Sat, 11 Nov 2023 23:56:27 +0000 (+0100) Subject: Fix undefined behaviour in datetime.time.fromisoformat() (#111982) X-Git-Tag: v3.13.0a2~118 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=21615f77b5a580e83589abae618dbe7c298700e2;p=thirdparty%2FPython%2Fcpython.git Fix undefined behaviour in datetime.time.fromisoformat() (#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). --- diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c index 9938ed5f8095..cb5403e8461f 100644 --- a/Modules/_datetimemodule.c +++ b/Modules/_datetimemodule.c @@ -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, µsecond, &tzoffset, &tzimicrosecond);