mirror of
https://github.com/python/cpython.git
synced 2025-08-02 16:13:13 +00:00
Closes #27710: Disallow fold not in [0, 1] in time and datetime constructors.
This commit is contained in:
parent
95e0df8389
commit
47649ab1f1
3 changed files with 36 additions and 11 deletions
|
@ -427,7 +427,7 @@ check_date_args(int year, int month, int day)
|
|||
* aren't, raise ValueError and return -1.
|
||||
*/
|
||||
static int
|
||||
check_time_args(int h, int m, int s, int us)
|
||||
check_time_args(int h, int m, int s, int us, int fold)
|
||||
{
|
||||
if (h < 0 || h > 23) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
|
@ -449,6 +449,11 @@ check_time_args(int h, int m, int s, int us)
|
|||
"microsecond must be in 0..999999");
|
||||
return -1;
|
||||
}
|
||||
if (fold != 0 && fold != 1) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"fold must be either 0 or 1");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -3598,7 +3603,7 @@ time_new(PyTypeObject *type, PyObject *args, PyObject *kw)
|
|||
if (PyArg_ParseTupleAndKeywords(args, kw, "|iiiiO$i", time_kws,
|
||||
&hour, &minute, &second, &usecond,
|
||||
&tzinfo, &fold)) {
|
||||
if (check_time_args(hour, minute, second, usecond) < 0)
|
||||
if (check_time_args(hour, minute, second, usecond, fold) < 0)
|
||||
return NULL;
|
||||
if (check_tzinfo_subclass(tzinfo) < 0)
|
||||
return NULL;
|
||||
|
@ -3926,8 +3931,14 @@ time_replace(PyDateTime_Time *self, PyObject *args, PyObject *kw)
|
|||
if (tuple == NULL)
|
||||
return NULL;
|
||||
clone = time_new(Py_TYPE(self), tuple, NULL);
|
||||
if (clone != NULL)
|
||||
if (clone != NULL) {
|
||||
if (fold != 0 && fold != 1) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"fold must be either 0 or 1");
|
||||
return NULL;
|
||||
}
|
||||
TIME_SET_FOLD(clone, fold);
|
||||
}
|
||||
Py_DECREF(tuple);
|
||||
return clone;
|
||||
}
|
||||
|
@ -4175,7 +4186,7 @@ datetime_new(PyTypeObject *type, PyObject *args, PyObject *kw)
|
|||
&second, &usecond, &tzinfo, &fold)) {
|
||||
if (check_date_args(year, month, day) < 0)
|
||||
return NULL;
|
||||
if (check_time_args(hour, minute, second, usecond) < 0)
|
||||
if (check_time_args(hour, minute, second, usecond, fold) < 0)
|
||||
return NULL;
|
||||
if (check_tzinfo_subclass(tzinfo) < 0)
|
||||
return NULL;
|
||||
|
@ -5006,8 +5017,15 @@ datetime_replace(PyDateTime_DateTime *self, PyObject *args, PyObject *kw)
|
|||
if (tuple == NULL)
|
||||
return NULL;
|
||||
clone = datetime_new(Py_TYPE(self), tuple, NULL);
|
||||
if (clone != NULL)
|
||||
|
||||
if (clone != NULL) {
|
||||
if (fold != 0 && fold != 1) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"fold must be either 0 or 1");
|
||||
return NULL;
|
||||
}
|
||||
DATE_SET_FOLD(clone, fold);
|
||||
}
|
||||
Py_DECREF(tuple);
|
||||
return clone;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue