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
0bd1a2dc
Commit
0bd1a2dc
authored
Sep 12, 2018
by
Oren Milman
Committed by
Serhiy Storchaka
Sep 12, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-31577: Fix a crash in os.utime() in case of a bad ns argument. (GH-3752)
parent
e5024517
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
0 deletions
+24
-0
Lib/test/test_os.py
Lib/test/test_os.py
+16
-0
Misc/NEWS.d/next/Core and Builtins/2017-09-25-20-36-24.bpo-31577.jgYsSA.rst
...ore and Builtins/2017-09-25-20-36-24.bpo-31577.jgYsSA.rst
+2
-0
Modules/posixmodule.c
Modules/posixmodule.c
+6
-0
No files found.
Lib/test/test_os.py
View file @
0bd1a2dc
...
...
@@ -635,6 +635,22 @@ class UtimeTests(unittest.TestCase):
with
self
.
assertRaises
(
ValueError
):
os
.
utime
(
self
.
fname
,
(
5
,
5
),
ns
=
(
5
,
5
))
@
support
.
cpython_only
def
test_issue31577
(
self
):
# The interpreter shouldn't crash in case utime() received a bad
# ns argument.
def
get_bad_int
(
divmod_ret_val
):
class
BadInt
:
def
__divmod__
(
*
args
):
return
divmod_ret_val
return
BadInt
()
with
self
.
assertRaises
(
TypeError
):
os
.
utime
(
self
.
fname
,
ns
=
(
get_bad_int
(
42
),
1
))
with
self
.
assertRaises
(
TypeError
):
os
.
utime
(
self
.
fname
,
ns
=
(
get_bad_int
(()),
1
))
with
self
.
assertRaises
(
TypeError
):
os
.
utime
(
self
.
fname
,
ns
=
(
get_bad_int
((
1
,
2
,
3
)),
1
))
from
test
import
mapping_tests
...
...
Misc/NEWS.d/next/Core and Builtins/2017-09-25-20-36-24.bpo-31577.jgYsSA.rst
0 → 100644
View file @
0bd1a2dc
Fix a crash in `os.utime()` in case of a bad ns argument. Patch by Oren
Milman.
Modules/posixmodule.c
View file @
0bd1a2dc
...
...
@@ -4630,6 +4630,12 @@ split_py_long_to_s_and_ns(PyObject *py_long, time_t *s, long *ns)
divmod
=
PyNumber_Divmod
(
py_long
,
billion
);
if
(
!
divmod
)
goto
exit
;
if
(
!
PyTuple_Check
(
divmod
)
||
PyTuple_GET_SIZE
(
divmod
)
!=
2
)
{
PyErr_Format
(
PyExc_TypeError
,
"%.200s.__divmod__() must return a 2-tuple, not %.200s"
,
Py_TYPE
(
py_long
)
->
tp_name
,
Py_TYPE
(
divmod
)
->
tp_name
);
goto
exit
;
}
*
s
=
_PyLong_AsTime_t
(
PyTuple_GET_ITEM
(
divmod
,
0
));
if
((
*
s
==
-
1
)
&&
PyErr_Occurred
())
goto
exit
;
...
...
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