Author: Ronan Lamy <[email protected]>
Branch: py3.6
Changeset: r97800:24c1cf8d6d14
Date: 2019-10-16 19:20 +0100
http://bitbucket.org/pypy/pypy/changeset/24c1cf8d6d14/
Log: reject null characters in a few more functions (bpo-13617)
diff --git a/lib_pypy/grp.py b/lib_pypy/grp.py
--- a/lib_pypy/grp.py
+++ b/lib_pypy/grp.py
@@ -47,12 +47,16 @@
# XXX maybe check error eventually
raise KeyError(gid)
return _group_from_gstruct(res)
+
@builtinify
def getgrnam(name):
if not isinstance(name, str):
raise TypeError("expected string")
+ name_b = os.fsencode(name)
+ if b'\0' in name_b:
+ raise ValueError("embedded null byte")
with _lock:
- res = lib.getgrnam(os.fsencode(name))
+ res = lib.getgrnam(name_b)
if not res:
raise KeyError("getgrnam(): name not found: %s" % name)
return _group_from_gstruct(res)
diff --git a/pypy/module/_locale/interp_locale.py
b/pypy/module/_locale/interp_locale.py
--- a/pypy/module/_locale/interp_locale.py
+++ b/pypy/module/_locale/interp_locale.py
@@ -98,6 +98,8 @@
s1, l1 = space.utf8_len_w(w_s1)
s2, l2 = space.utf8_len_w(w_s2)
+ if '\x00' in s1 or '\x00' in s2:
+ raise oefmt(space.w_ValueError, "embedded null character")
s1_c = rffi.utf82wcharp(s1, l1)
s2_c = rffi.utf82wcharp(s2, l2)
@@ -112,7 +114,7 @@
_strxfrm = rlocale.external('strxfrm',
[rffi.CCHARP, rffi.CCHARP, rffi.SIZE_T], rffi.SIZE_T)
-@unwrap_spec(s='text')
+@unwrap_spec(s='text0')
def strxfrm(space, s):
"string -> string. Returns a string that behaves for cmp locale-aware."
n1 = len(s) + 1
diff --git a/pypy/module/_locale/test/test_locale.py
b/pypy/module/_locale/test/test_locale.py
--- a/pypy/module/_locale/test/test_locale.py
+++ b/pypy/module/_locale/test/test_locale.py
@@ -49,8 +49,8 @@
def teardown_class(cls):
import _locale
_locale.setlocale(_locale.LC_ALL, cls.oldlocale)
-
-
+
+
def test_import(self):
import _locale
@@ -58,7 +58,7 @@
import locale
assert locale
-
+
def test_constants(self):
import sys
@@ -82,7 +82,7 @@
)
import _locale
-
+
for constant in _CONSTANTS:
assert hasattr(_locale, constant)
@@ -171,7 +171,10 @@
assert a is not b
assert a == b
- raises(TypeError, _locale.strxfrm, 1)
+ with raises(TypeError):
+ _locale.strxfrm(1)
+ with raises(ValueError):
+ _locale.strxfrm("a\x00b")
_locale.setlocale(_locale.LC_ALL, self.language_pl)
a = "1234"
@@ -271,7 +274,7 @@
raises(ValueError, _locale.nl_langinfo, 12345)
raises(TypeError, _locale.nl_langinfo, None)
-
+
def test_bindtextdomain(self):
import sys
if sys.platform == 'win32':
diff --git a/pypy/module/time/interp_time.py b/pypy/module/time/interp_time.py
--- a/pypy/module/time/interp_time.py
+++ b/pypy/module/time/interp_time.py
@@ -837,7 +837,7 @@
# reset timezone, altzone, daylight and tzname
_init_timezone(space)
-@unwrap_spec(format='text')
+@unwrap_spec(format='text0')
def strftime(space, format, w_tup=None):
"""strftime(format[, tuple]) -> string
diff --git a/pypy/module/time/test/test_time.py
b/pypy/module/time/test/test_time.py
--- a/pypy/module/time/test/test_time.py
+++ b/pypy/module/time/test/test_time.py
@@ -315,6 +315,8 @@
else:
assert time.strftime('%f') == '%f'
expected_year = '0'
+ with raises(ValueError):
+ time.strftime("%Y\0", tt)
expected_formatted_date = expected_year + ' 01 01 00 00 00 1 001'
assert time.strftime("%Y %m %d %H %M %S %w %j", (0,) * 9) ==
expected_formatted_date
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit