diff options
author | Oren Milman <orenmn@gmail.com> | 2017-08-20 15:35:36 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2017-08-20 15:35:36 (GMT) |
commit | 1d1d3e9db882d78433f5bc8dbe7df929f4b6b5e1 (patch) | |
tree | b5d3ee0a0aba15a2586c4e891630554dd702e933 /Modules/timemodule.c | |
parent | 4bfebc63012f0f4e00f6a98c3d96e1c0ebe93408 (diff) | |
download | cpython-1d1d3e9db882d78433f5bc8dbe7df929f4b6b5e1.zip cpython-1d1d3e9db882d78433f5bc8dbe7df929f4b6b5e1.tar.gz cpython-1d1d3e9db882d78433f5bc8dbe7df929f4b6b5e1.tar.bz2 |
bpo-28261: Fixed err msgs where PyArg_ParseTuple is used to parse normal tuples. (#3119)
Diffstat (limited to 'Modules/timemodule.c')
-rw-r--r-- | Modules/timemodule.c | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/Modules/timemodule.c b/Modules/timemodule.c index 15c467b..36a95bb 100644 --- a/Modules/timemodule.c +++ b/Modules/timemodule.c @@ -415,7 +415,7 @@ When 'seconds' is not passed in, convert the current time instead."); * an exception and return 0 on error. */ static int -gettmarg(PyObject *args, struct tm *p) +gettmarg(PyObject *args, struct tm *p, const char *format) { int y; @@ -427,7 +427,7 @@ gettmarg(PyObject *args, struct tm *p) return 0; } - if (!PyArg_ParseTuple(args, "iiiiiiiii", + if (!PyArg_ParseTuple(args, format, &y, &p->tm_mon, &p->tm_mday, &p->tm_hour, &p->tm_min, &p->tm_sec, &p->tm_wday, &p->tm_yday, &p->tm_isdst)) @@ -586,8 +586,12 @@ time_strftime(PyObject *self, PyObject *args) if (_PyTime_localtime(tt, &buf) != 0) return NULL; } - else if (!gettmarg(tup, &buf) || !checktm(&buf)) + else if (!gettmarg(tup, &buf, + "iiiiiiiii;strftime(): illegal time tuple argument") || + !checktm(&buf)) + { return NULL; + } #if defined(_MSC_VER) || defined(sun) || defined(_AIX) if (buf.tm_year + 1900 < 1 || 9999 < buf.tm_year + 1900) { @@ -776,9 +780,13 @@ time_asctime(PyObject *self, PyObject *args) time_t tt = time(NULL); if (_PyTime_localtime(tt, &buf) != 0) return NULL; - - } else if (!gettmarg(tup, &buf) || !checktm(&buf)) + } + else if (!gettmarg(tup, &buf, + "iiiiiiiii;asctime(): illegal time tuple argument") || + !checktm(&buf)) + { return NULL; + } return _asctime(&buf); } @@ -814,8 +822,11 @@ time_mktime(PyObject *self, PyObject *tup) { struct tm buf; time_t tt; - if (!gettmarg(tup, &buf)) + if (!gettmarg(tup, &buf, + "iiiiiiiii;mktime(): illegal time tuple argument")) + { return NULL; + } #ifdef _AIX /* year < 1902 or year > 2037 */ if (buf.tm_year < 2 || buf.tm_year > 137) { |