[pypy-commit] cffi default: Test and fix: a negative size was implicitly converted to a huge size_t
arigo
noreply at buildbot.pypy.org
Fri Oct 9 09:57:26 CEST 2015
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r2333:2a9a1726dae3
Date: 2015-10-09 09:58 +0200
http://bitbucket.org/cffi/cffi/changeset/2a9a1726dae3/
Log: Test and fix: a negative size was implicitly converted to a huge
size_t number
diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c
--- a/c/_cffi_backend.c
+++ b/c/_cffi_backend.c
@@ -5822,6 +5822,10 @@
if (!PyArg_ParseTupleAndKeywords(args, kwds, "OOn", keywords,
&dest_obj, &src_obj, &n))
return NULL;
+ if (n < 0) {
+ PyErr_SetString(PyExc_ValueError, "negative size");
+ return NULL;
+ }
if (_fetch_as_buffer(src_obj, &src_view, 0) < 0) {
return NULL;
diff --git a/c/test_c.py b/c/test_c.py
--- a/c/test_c.py
+++ b/c/test_c.py
@@ -3450,7 +3450,6 @@
assert b.tolist() == [-997, -996, 995]
def test_memmove_readonly_readwrite():
- ffi = FFI()
SignedChar = new_primitive_type("signed char")
SignedCharA = new_array_type(new_pointer_type(SignedChar), None)
p = newp(SignedCharA, 5)
@@ -3463,6 +3462,12 @@
memmove(dest=ba, src=p, n=3)
assert ba == bytearray(b"ABcxx")
+def test_memmove_sign_check():
+ SignedChar = new_primitive_type("signed char")
+ SignedCharA = new_array_type(new_pointer_type(SignedChar), None)
+ p = newp(SignedCharA, 5)
+ py.test.raises(ValueError, memmove, p, p + 1, -1) # not segfault
+
def test_dereference_null_ptr():
BInt = new_primitive_type("int")
BIntPtr = new_pointer_type(BInt)
More information about the pypy-commit
mailing list