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
2b0d2007
Commit
2b0d2007
authored
Apr 20, 2015
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #23908: os functions now reject paths with embedded null character
on Windows instead of silently truncate them.
parent
2ef7c478
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
50 additions
and
7 deletions
+50
-7
Lib/test/test_posix.py
Lib/test/test_posix.py
+36
-0
Misc/NEWS
Misc/NEWS
+3
-0
Modules/_io/fileio.c
Modules/_io/fileio.c
+6
-7
Modules/posixmodule.c
Modules/posixmodule.c
+5
-0
No files found.
Lib/test/test_posix.py
View file @
2b0d2007
...
@@ -1169,6 +1169,42 @@ class PosixTester(unittest.TestCase):
...
@@ -1169,6 +1169,42 @@ class PosixTester(unittest.TestCase):
else
:
else
:
self
.
fail
(
"No valid path_error2() test for os."
+
name
)
self
.
fail
(
"No valid path_error2() test for os."
+
name
)
def
test_path_with_null_character
(
self
):
fn
=
support
.
TESTFN
fn_with_NUL
=
fn
+
'
\
0
'
self
.
addCleanup
(
support
.
unlink
,
fn
)
support
.
unlink
(
fn
)
fd
=
None
try
:
with
self
.
assertRaises
(
TypeError
):
fd
=
os
.
open
(
fn_with_NUL
,
os
.
O_WRONLY
|
os
.
O_CREAT
)
# raises
finally
:
if
fd
is
not
None
:
os
.
close
(
fd
)
self
.
assertFalse
(
os
.
path
.
exists
(
fn
))
self
.
assertRaises
(
TypeError
,
os
.
mkdir
,
fn_with_NUL
)
self
.
assertFalse
(
os
.
path
.
exists
(
fn
))
open
(
fn
,
'wb'
).
close
()
self
.
assertRaises
(
TypeError
,
os
.
stat
,
fn_with_NUL
)
def
test_path_with_null_byte
(
self
):
fn
=
os
.
fsencode
(
support
.
TESTFN
)
fn_with_NUL
=
fn
+
b'
\
0
'
self
.
addCleanup
(
support
.
unlink
,
fn
)
support
.
unlink
(
fn
)
fd
=
None
try
:
with
self
.
assertRaises
(
ValueError
):
fd
=
os
.
open
(
fn_with_NUL
,
os
.
O_WRONLY
|
os
.
O_CREAT
)
# raises
finally
:
if
fd
is
not
None
:
os
.
close
(
fd
)
self
.
assertFalse
(
os
.
path
.
exists
(
fn
))
self
.
assertRaises
(
ValueError
,
os
.
mkdir
,
fn_with_NUL
)
self
.
assertFalse
(
os
.
path
.
exists
(
fn
))
open
(
fn
,
'wb'
).
close
()
self
.
assertRaises
(
ValueError
,
os
.
stat
,
fn_with_NUL
)
class
PosixGroupsTester
(
unittest
.
TestCase
):
class
PosixGroupsTester
(
unittest
.
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
...
...
Misc/NEWS
View file @
2b0d2007
...
@@ -29,6 +29,9 @@ Core and Builtins
...
@@ -29,6 +29,9 @@ Core and Builtins
Library
Library
-------
-------
- Issue #23908: os functions now reject paths with embedded null character
on Windows instead of silently truncate them.
- Issue #23728: binascii.crc_hqx() could return an integer outside of the range
- Issue #23728: binascii.crc_hqx() could return an integer outside of the range
0-0xffff for empty data.
0-0xffff for empty data.
...
...
Modules/_io/fileio.c
View file @
2b0d2007
...
@@ -275,15 +275,14 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
...
@@ -275,15 +275,14 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
#ifdef MS_WINDOWS
#ifdef MS_WINDOWS
if
(
PyUnicode_Check
(
nameobj
))
{
if
(
PyUnicode_Check
(
nameobj
))
{
int
rv
=
_PyUnicode_HasNULChars
(
nameobj
);
Py_ssize_t
length
;
if
(
rv
)
{
widename
=
PyUnicode_AsUnicodeAndSize
(
nameobj
,
&
length
);
if
(
rv
!=
-
1
)
if
(
widename
==
NULL
)
return
-
1
;
if
(
wcslen
(
widename
)
!=
length
)
{
PyErr_SetString
(
PyExc_TypeError
,
"embedded NUL character"
);
PyErr_SetString
(
PyExc_TypeError
,
"embedded NUL character"
);
return
-
1
;
return
-
1
;
}
}
widename
=
PyUnicode_AsUnicode
(
nameobj
);
if
(
widename
==
NULL
)
return
-
1
;
}
else
}
else
#endif
#endif
if
(
fd
<
0
)
if
(
fd
<
0
)
...
...
Modules/posixmodule.c
View file @
2b0d2007
...
@@ -858,6 +858,11 @@ path_converter(PyObject *o, void *p) {
...
@@ -858,6 +858,11 @@ path_converter(PyObject *o, void *p) {
Py_DECREF
(
unicode
);
Py_DECREF
(
unicode
);
return
0
;
return
0
;
}
}
if
(
wcslen
(
wide
)
!=
length
)
{
FORMAT_EXCEPTION
(
PyExc_TypeError
,
"embedded null character"
);
Py_DECREF
(
unicode
);
return
0
;
}
path
->
wide
=
wide
;
path
->
wide
=
wide
;
path
->
narrow
=
NULL
;
path
->
narrow
=
NULL
;
...
...
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