Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
d5b0c9b8
Commit
d5b0c9b8
authored
Mar 20, 2006
by
Neal Norwitz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix problem spotted by Coverity that occurs if tzinfo.tzname().replace()
returns a non-string when converting %Z. Will backport.
parent
29892cc3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
4 deletions
+20
-4
Lib/test/test_datetime.py
Lib/test/test_datetime.py
+11
-0
Modules/datetimemodule.c
Modules/datetimemodule.c
+9
-4
No files found.
Lib/test/test_datetime.py
View file @
d5b0c9b8
...
...
@@ -1168,6 +1168,17 @@ class TestDateTime(TestDate):
self
.
assertEqual
(
dt2
-
dt1
,
us
)
self
.
assert_
(
dt1
<
dt2
)
def
test_strftime_with_bad_tzname_replace
(
self
):
# verify ok if tzinfo.tzname().replace() returns a non-string
class
MyTzInfo
(
FixedOffset
):
def
tzname
(
self
,
dt
):
class
MyStr
(
str
):
def
replace
(
self
,
*
args
):
return
None
return
MyStr
(
'name'
)
t
=
self
.
theclass
(
2005
,
3
,
2
,
0
,
0
,
0
,
0
,
MyTzInfo
(
3
,
'name'
))
self
.
assertRaises
(
TypeError
,
t
.
strftime
,
'%Z'
)
def
test_bad_constructor_arguments
(
self
):
# bad years
self
.
theclass
(
MINYEAR
,
1
,
1
)
# no exception
...
...
Modules/datetimemodule.c
View file @
d5b0c9b8
...
...
@@ -1228,8 +1228,8 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple,
}
}
assert
(
zreplacement
!=
NULL
);
ptoappend
=
PyString_A
sString
(
zreplacement
);
ntoappend
=
PyString_
Size
(
zreplacement
);
ptoappend
=
PyString_A
S_STRING
(
zreplacement
);
ntoappend
=
PyString_
GET_SIZE
(
zreplacement
);
}
else
if
(
ch
==
'Z'
)
{
/* format tzname */
...
...
@@ -1257,14 +1257,18 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple,
Py_DECREF
(
temp
);
if
(
Zreplacement
==
NULL
)
goto
Done
;
if
(
!
PyString_Check
(
Zreplacement
))
{
PyErr_SetString
(
PyExc_TypeError
,
"tzname.replace() did not return a string"
);
goto
Done
;
}
}
else
Py_DECREF
(
temp
);
}
}
assert
(
Zreplacement
!=
NULL
);
ptoappend
=
PyString_A
sString
(
Zreplacement
);
ntoappend
=
PyString_
Size
(
Zreplacement
);
ptoappend
=
PyString_A
S_STRING
(
Zreplacement
);
ntoappend
=
PyString_
GET_SIZE
(
Zreplacement
);
}
else
{
/* percent followed by neither z nor Z */
...
...
@@ -1275,6 +1279,7 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple,
/* Append the ntoappend chars starting at ptoappend to
* the new format.
*/
assert
(
ptoappend
!=
NULL
);
assert
(
ntoappend
>=
0
);
if
(
ntoappend
==
0
)
continue
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment