Karsten Hopp 47ba31
To: vim_dev@googlegroups.com
Karsten Hopp 47ba31
Subject: Patch 7.3.657
Karsten Hopp 47ba31
Fcc: outbox
Karsten Hopp 47ba31
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp 47ba31
Mime-Version: 1.0
Karsten Hopp 47ba31
Content-Type: text/plain; charset=UTF-8
Karsten Hopp 47ba31
Content-Transfer-Encoding: 8bit
Karsten Hopp 47ba31
------------
Karsten Hopp 47ba31
Karsten Hopp 47ba31
Patch 7.3.657
Karsten Hopp 47ba31
Problem:    Python bindings silently truncate string values containing NUL.
Karsten Hopp 47ba31
Solution:   Fail when a string contains NUL. (ZyX)
Karsten Hopp 47ba31
Files:      src/if_python.c, src/if_python3.c
Karsten Hopp 47ba31
Karsten Hopp 47ba31
Karsten Hopp 47ba31
*** ../vim-7.3.656/src/if_python.c	2012-09-05 18:54:37.000000000 +0200
Karsten Hopp 47ba31
--- src/if_python.c	2012-09-05 19:02:07.000000000 +0200
Karsten Hopp 47ba31
***************
Karsten Hopp 47ba31
*** 191,196 ****
Karsten Hopp 47ba31
--- 191,197 ----
Karsten Hopp 47ba31
  # define PyRun_SimpleString dll_PyRun_SimpleString
Karsten Hopp 47ba31
  # define PyRun_String dll_PyRun_String
Karsten Hopp 47ba31
  # define PyString_AsString dll_PyString_AsString
Karsten Hopp 47ba31
+ # define PyString_AsStringAndSize dll_PyString_AsStringAndSize
Karsten Hopp 47ba31
  # define PyString_FromString dll_PyString_FromString
Karsten Hopp 47ba31
  # define PyString_FromStringAndSize dll_PyString_FromStringAndSize
Karsten Hopp 47ba31
  # define PyString_Size dll_PyString_Size
Karsten Hopp 47ba31
***************
Karsten Hopp 47ba31
*** 288,293 ****
Karsten Hopp 47ba31
--- 289,295 ----
Karsten Hopp 47ba31
  static int(*dll_PyRun_SimpleString)(char *);
Karsten Hopp 47ba31
  static PyObject *(*dll_PyRun_String)(char *, int, PyObject *, PyObject *);
Karsten Hopp 47ba31
  static char*(*dll_PyString_AsString)(PyObject *);
Karsten Hopp 47ba31
+ static int(*dll_PyString_AsStringAndSize)(PyObject *, char **, int *);
Karsten Hopp 47ba31
  static PyObject*(*dll_PyString_FromString)(const char *);
Karsten Hopp 47ba31
  static PyObject*(*dll_PyString_FromStringAndSize)(const char *, PyInt);
Karsten Hopp 47ba31
  static PyInt(*dll_PyString_Size)(PyObject *);
Karsten Hopp 47ba31
***************
Karsten Hopp 47ba31
*** 406,411 ****
Karsten Hopp 47ba31
--- 408,414 ----
Karsten Hopp 47ba31
      {"PyRun_SimpleString", (PYTHON_PROC*)&dll_PyRun_SimpleString},
Karsten Hopp 47ba31
      {"PyRun_String", (PYTHON_PROC*)&dll_PyRun_String},
Karsten Hopp 47ba31
      {"PyString_AsString", (PYTHON_PROC*)&dll_PyString_AsString},
Karsten Hopp 47ba31
+     {"PyString_AsStringAndSize", (PYTHON_PROC*)&dll_PyString_AsStringAndSize},
Karsten Hopp 47ba31
      {"PyString_FromString", (PYTHON_PROC*)&dll_PyString_FromString},
Karsten Hopp 47ba31
      {"PyString_FromStringAndSize", (PYTHON_PROC*)&dll_PyString_FromStringAndSize},
Karsten Hopp 47ba31
      {"PyString_Size", (PYTHON_PROC*)&dll_PyString_Size},
Karsten Hopp 47ba31
***************
Karsten Hopp 47ba31
*** 578,591 ****
Karsten Hopp 47ba31
  static int initialised = 0;
Karsten Hopp 47ba31
  #define PYINITIALISED initialised
Karsten Hopp 47ba31
  
Karsten Hopp 47ba31
- /* Add conversion from PyInt? */
Karsten Hopp 47ba31
  #define DICTKEY_GET(err) \
Karsten Hopp 47ba31
      if (!PyString_Check(keyObject)) \
Karsten Hopp 47ba31
      { \
Karsten Hopp 47ba31
  	PyErr_SetString(PyExc_TypeError, _("only string keys are allowed")); \
Karsten Hopp 47ba31
  	return err; \
Karsten Hopp 47ba31
      } \
Karsten Hopp 47ba31
!     key = (char_u *) PyString_AsString(keyObject);
Karsten Hopp 47ba31
  #define DICTKEY_UNREF
Karsten Hopp 47ba31
  #define DICTKEY_DECL
Karsten Hopp 47ba31
  
Karsten Hopp 47ba31
--- 581,595 ----
Karsten Hopp 47ba31
  static int initialised = 0;
Karsten Hopp 47ba31
  #define PYINITIALISED initialised
Karsten Hopp 47ba31
  
Karsten Hopp 47ba31
  #define DICTKEY_GET(err) \
Karsten Hopp 47ba31
      if (!PyString_Check(keyObject)) \
Karsten Hopp 47ba31
      { \
Karsten Hopp 47ba31
  	PyErr_SetString(PyExc_TypeError, _("only string keys are allowed")); \
Karsten Hopp 47ba31
  	return err; \
Karsten Hopp 47ba31
      } \
Karsten Hopp 47ba31
!     if (PyString_AsStringAndSize(keyObject, (char **) &key, NULL) == -1) \
Karsten Hopp 47ba31
! 	return err;
Karsten Hopp 47ba31
! 
Karsten Hopp 47ba31
  #define DICTKEY_UNREF
Karsten Hopp 47ba31
  #define DICTKEY_DECL
Karsten Hopp 47ba31
  
Karsten Hopp 47ba31
*** ../vim-7.3.656/src/if_python3.c	2012-09-05 18:54:37.000000000 +0200
Karsten Hopp 47ba31
--- src/if_python3.c	2012-09-05 19:02:07.000000000 +0200
Karsten Hopp 47ba31
***************
Karsten Hopp 47ba31
*** 172,177 ****
Karsten Hopp 47ba31
--- 172,178 ----
Karsten Hopp 47ba31
  # define PyUnicode_AsEncodedString py3_PyUnicode_AsEncodedString
Karsten Hopp 47ba31
  # undef PyBytes_AsString
Karsten Hopp 47ba31
  # define PyBytes_AsString py3_PyBytes_AsString
Karsten Hopp 47ba31
+ # define PyBytes_AsStringAndSize py3_PyBytes_AsStringAndSize
Karsten Hopp 47ba31
  # undef PyBytes_FromString
Karsten Hopp 47ba31
  # define PyBytes_FromString py3_PyBytes_FromString
Karsten Hopp 47ba31
  # define PyFloat_FromDouble py3_PyFloat_FromDouble
Karsten Hopp 47ba31
***************
Karsten Hopp 47ba31
*** 273,278 ****
Karsten Hopp 47ba31
--- 274,280 ----
Karsten Hopp 47ba31
  static char* (*py3__PyUnicode_AsString)(PyObject *unicode);
Karsten Hopp 47ba31
  static PyObject* (*py3_PyUnicode_AsEncodedString)(PyObject *unicode, const char* encoding, const char* errors);
Karsten Hopp 47ba31
  static char* (*py3_PyBytes_AsString)(PyObject *bytes);
Karsten Hopp 47ba31
+ static int (*py3_PyBytes_AsStringAndSize)(PyObject *bytes, char **buffer, int *length);
Karsten Hopp 47ba31
  static PyObject* (*py3_PyBytes_FromString)(char *str);
Karsten Hopp 47ba31
  static PyObject* (*py3_PyFloat_FromDouble)(double num);
Karsten Hopp 47ba31
  static double (*py3_PyFloat_AsDouble)(PyObject *);
Karsten Hopp 47ba31
***************
Karsten Hopp 47ba31
*** 379,384 ****
Karsten Hopp 47ba31
--- 381,387 ----
Karsten Hopp 47ba31
      {"PyImport_AppendInittab", (PYTHON_PROC*)&py3_PyImport_AppendInittab},
Karsten Hopp 47ba31
      {"_PyUnicode_AsString", (PYTHON_PROC*)&py3__PyUnicode_AsString},
Karsten Hopp 47ba31
      {"PyBytes_AsString", (PYTHON_PROC*)&py3_PyBytes_AsString},
Karsten Hopp 47ba31
+     {"PyBytes_AsStringAndSize", (PYTHON_PROC*)&py3_PyBytes_AsStringAndSize},
Karsten Hopp 47ba31
      {"PyBytes_FromString", (PYTHON_PROC*)&py3_PyBytes_FromString},
Karsten Hopp 47ba31
      {"PyFloat_FromDouble", (PYTHON_PROC*)&py3_PyFloat_FromDouble},
Karsten Hopp 47ba31
      {"PyFloat_AsDouble", (PYTHON_PROC*)&py3_PyFloat_AsDouble},
Karsten Hopp 47ba31
***************
Karsten Hopp 47ba31
*** 544,560 ****
Karsten Hopp 47ba31
  
Karsten Hopp 47ba31
  #define PYINITIALISED py3initialised
Karsten Hopp 47ba31
  
Karsten Hopp 47ba31
! /* Add conversion from PyInt? */
Karsten Hopp 47ba31
  #define DICTKEY_GET(err) \
Karsten Hopp 47ba31
      if (PyBytes_Check(keyObject)) \
Karsten Hopp 47ba31
! 	key = (char_u *) PyBytes_AsString(keyObject); \
Karsten Hopp 47ba31
      else if (PyUnicode_Check(keyObject)) \
Karsten Hopp 47ba31
      { \
Karsten Hopp 47ba31
  	bytes = PyString_AsBytes(keyObject); \
Karsten Hopp 47ba31
  	if (bytes == NULL) \
Karsten Hopp 47ba31
  	    return err; \
Karsten Hopp 47ba31
! 	key = (char_u *) PyBytes_AsString(bytes); \
Karsten Hopp 47ba31
! 	if (key == NULL) \
Karsten Hopp 47ba31
  	    return err; \
Karsten Hopp 47ba31
      } \
Karsten Hopp 47ba31
      else \
Karsten Hopp 47ba31
--- 547,566 ----
Karsten Hopp 47ba31
  
Karsten Hopp 47ba31
  #define PYINITIALISED py3initialised
Karsten Hopp 47ba31
  
Karsten Hopp 47ba31
! #define DICTKEY_DECL PyObject *bytes = NULL;
Karsten Hopp 47ba31
! 
Karsten Hopp 47ba31
  #define DICTKEY_GET(err) \
Karsten Hopp 47ba31
      if (PyBytes_Check(keyObject)) \
Karsten Hopp 47ba31
!     { \
Karsten Hopp 47ba31
! 	if (PyBytes_AsStringAndSize(keyObject, (char **) &key, NULL) == -1) \
Karsten Hopp 47ba31
! 	    return err; \
Karsten Hopp 47ba31
!     } \
Karsten Hopp 47ba31
      else if (PyUnicode_Check(keyObject)) \
Karsten Hopp 47ba31
      { \
Karsten Hopp 47ba31
  	bytes = PyString_AsBytes(keyObject); \
Karsten Hopp 47ba31
  	if (bytes == NULL) \
Karsten Hopp 47ba31
  	    return err; \
Karsten Hopp 47ba31
! 	if (PyBytes_AsStringAndSize(bytes, (char **) &key, NULL) == -1) \
Karsten Hopp 47ba31
  	    return err; \
Karsten Hopp 47ba31
      } \
Karsten Hopp 47ba31
      else \
Karsten Hopp 47ba31
***************
Karsten Hopp 47ba31
*** 562,573 ****
Karsten Hopp 47ba31
  	PyErr_SetString(PyExc_TypeError, _("only string keys are allowed")); \
Karsten Hopp 47ba31
  	return err; \
Karsten Hopp 47ba31
      }
Karsten Hopp 47ba31
  #define DICTKEY_UNREF \
Karsten Hopp 47ba31
      if (bytes != NULL) \
Karsten Hopp 47ba31
  	Py_XDECREF(bytes);
Karsten Hopp 47ba31
  
Karsten Hopp 47ba31
- #define DICTKEY_DECL PyObject *bytes = NULL;
Karsten Hopp 47ba31
- 
Karsten Hopp 47ba31
  /*
Karsten Hopp 47ba31
   * Include the code shared with if_python.c
Karsten Hopp 47ba31
   */
Karsten Hopp 47ba31
--- 568,578 ----
Karsten Hopp 47ba31
  	PyErr_SetString(PyExc_TypeError, _("only string keys are allowed")); \
Karsten Hopp 47ba31
  	return err; \
Karsten Hopp 47ba31
      }
Karsten Hopp 47ba31
+ 
Karsten Hopp 47ba31
  #define DICTKEY_UNREF \
Karsten Hopp 47ba31
      if (bytes != NULL) \
Karsten Hopp 47ba31
  	Py_XDECREF(bytes);
Karsten Hopp 47ba31
  
Karsten Hopp 47ba31
  /*
Karsten Hopp 47ba31
   * Include the code shared with if_python.c
Karsten Hopp 47ba31
   */
Karsten Hopp 47ba31
*** ../vim-7.3.656/src/version.c	2012-09-05 18:54:37.000000000 +0200
Karsten Hopp 47ba31
--- src/version.c	2012-09-05 19:03:03.000000000 +0200
Karsten Hopp 47ba31
***************
Karsten Hopp 47ba31
*** 721,722 ****
Karsten Hopp 47ba31
--- 721,724 ----
Karsten Hopp 47ba31
  {   /* Add new patch number below this line */
Karsten Hopp 47ba31
+ /**/
Karsten Hopp 47ba31
+     657,
Karsten Hopp 47ba31
  /**/
Karsten Hopp 47ba31
Karsten Hopp 47ba31
-- 
Karsten Hopp 47ba31
Have you heard about the new Barbie doll?  It's called Divorce
Karsten Hopp 47ba31
Barbie.  It comes with all of Ken's stuff.
Karsten Hopp 47ba31
Karsten Hopp 47ba31
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp 47ba31
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp 47ba31
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
Karsten Hopp 47ba31
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///