diff options
author | Bram Moolenaar <Bram@vim.org> | 2012-09-05 19:09:11 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2012-09-05 19:09:11 +0200 |
commit | afa6b9af865c18dd865ccf7b804a4645570027bd (patch) | |
tree | c8f8f1be55f7f585f5290ba87da9f6599899ab31 /src/if_py_both.h | |
parent | cdab9051368a6437b7e40df673594147425df751 (diff) | |
download | vim-afa6b9af865c18dd865ccf7b804a4645570027bd.zip |
updated for version 7.3.658
Problem: NUL bytes truncate strings when converted from Python.
Solution: Handle truncation as an error. (ZyX)
Diffstat (limited to 'src/if_py_both.h')
-rw-r--r-- | src/if_py_both.h | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/if_py_both.h b/src/if_py_both.h index 3ab18516e..0031003ed 100644 --- a/src/if_py_both.h +++ b/src/if_py_both.h @@ -2530,8 +2530,10 @@ _ConvertFromPyObject(PyObject *obj, typval_T *tv, PyObject *lookupDict) #if PY_MAJOR_VERSION >= 3 else if (PyBytes_Check(obj)) { - char_u *result = (char_u *) PyBytes_AsString(obj); + char_u *result; + if (PyString_AsStringAndSize(obj, (char **) &result, NULL) == -1) + return -1; if (result == NULL) return -1; @@ -2549,7 +2551,8 @@ _ConvertFromPyObject(PyObject *obj, typval_T *tv, PyObject *lookupDict) if (bytes == NULL) return -1; - result = (char_u *) PyBytes_AsString(bytes); + if(PyString_AsStringAndSize(bytes, (char **) &result, NULL) == -1) + return -1; if (result == NULL) return -1; @@ -2572,7 +2575,8 @@ _ConvertFromPyObject(PyObject *obj, typval_T *tv, PyObject *lookupDict) if (bytes == NULL) return -1; - result=(char_u *) PyString_AsString(bytes); + if(PyString_AsStringAndSize(bytes, (char **) &result, NULL) == -1) + return -1; if (result == NULL) return -1; @@ -2587,8 +2591,10 @@ _ConvertFromPyObject(PyObject *obj, typval_T *tv, PyObject *lookupDict) } else if (PyString_Check(obj)) { - char_u *result = (char_u *) PyString_AsString(obj); + char_u *result; + if(PyString_AsStringAndSize(obj, (char **) &result, NULL) == -1) + return -1; if (result == NULL) return -1; |