Blob Blame History Raw
To: vim_dev@googlegroups.com
Subject: Patch 7.3.658
Fcc: outbox
From: Bram Moolenaar <Bram@moolenaar.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
------------

Patch 7.3.658
Problem:    NUL bytes truncate strings when converted from Python.
Solution:   Handle truncation as an error. (ZyX)
Files:	    src/if_py_both.h, src/if_python3.c


*** ../vim-7.3.657/src/if_py_both.h	2012-09-05 18:45:24.000000000 +0200
--- src/if_py_both.h	2012-09-05 19:05:27.000000000 +0200
***************
*** 2530,2537 ****
  #if PY_MAJOR_VERSION >= 3
      else if (PyBytes_Check(obj))
      {
! 	char_u	*result = (char_u *) PyBytes_AsString(obj);
  
  	if (result == NULL)
  	    return -1;
  
--- 2530,2539 ----
  #if PY_MAJOR_VERSION >= 3
      else if (PyBytes_Check(obj))
      {
! 	char_u	*result;
  
+ 	if (PyString_AsStringAndSize(obj, (char **) &result, NULL) == -1)
+ 	    return -1;
  	if (result == NULL)
  	    return -1;
  
***************
*** 2549,2555 ****
  	if (bytes == NULL)
  	    return -1;
  
! 	result = (char_u *) PyBytes_AsString(bytes);
  	if (result == NULL)
  	    return -1;
  
--- 2551,2558 ----
  	if (bytes == NULL)
  	    return -1;
  
! 	if(PyString_AsStringAndSize(bytes, (char **) &result, NULL) == -1)
! 	    return -1;
  	if (result == NULL)
  	    return -1;
  
***************
*** 2572,2578 ****
  	if (bytes == NULL)
  	    return -1;
  
! 	result=(char_u *) PyString_AsString(bytes);
  	if (result == NULL)
  	    return -1;
  
--- 2575,2582 ----
  	if (bytes == NULL)
  	    return -1;
  
! 	if(PyString_AsStringAndSize(bytes, (char **) &result, NULL) == -1)
! 	    return -1;
  	if (result == NULL)
  	    return -1;
  
***************
*** 2587,2594 ****
      }
      else if (PyString_Check(obj))
      {
! 	char_u	*result = (char_u *) PyString_AsString(obj);
  
  	if (result == NULL)
  	    return -1;
  
--- 2591,2600 ----
      }
      else if (PyString_Check(obj))
      {
! 	char_u	*result;
  
+ 	if(PyString_AsStringAndSize(obj, (char **) &result, NULL) == -1)
+ 	    return -1;
  	if (result == NULL)
  	    return -1;
  
*** ../vim-7.3.657/src/if_python3.c	2012-09-05 19:03:51.000000000 +0200
--- src/if_python3.c	2012-09-05 19:05:27.000000000 +0200
***************
*** 85,90 ****
--- 85,91 ----
  #define PyString_AsString(obj) PyBytes_AsString(obj)
  #define PyString_Size(obj) PyBytes_GET_SIZE(bytes)
  #define PyString_FromString(repr) PyUnicode_FromString(repr)
+ #define PyString_AsStringAndSize(obj, buffer, len) PyBytes_AsStringAndSize(obj, buffer, len)
  
  #if defined(DYNAMIC_PYTHON3) || defined(PROTO)
  
***************
*** 552,558 ****
  #define DICTKEY_GET(err) \
      if (PyBytes_Check(keyObject)) \
      { \
! 	if (PyBytes_AsStringAndSize(keyObject, (char **) &key, NULL) == -1) \
  	    return err; \
      } \
      else if (PyUnicode_Check(keyObject)) \
--- 553,559 ----
  #define DICTKEY_GET(err) \
      if (PyBytes_Check(keyObject)) \
      { \
! 	if (PyString_AsStringAndSize(keyObject, (char **) &key, NULL) == -1) \
  	    return err; \
      } \
      else if (PyUnicode_Check(keyObject)) \
***************
*** 560,566 ****
  	bytes = PyString_AsBytes(keyObject); \
  	if (bytes == NULL) \
  	    return err; \
! 	if (PyBytes_AsStringAndSize(bytes, (char **) &key, NULL) == -1) \
  	    return err; \
      } \
      else \
--- 561,567 ----
  	bytes = PyString_AsBytes(keyObject); \
  	if (bytes == NULL) \
  	    return err; \
! 	if (PyString_AsStringAndSize(bytes, (char **) &key, NULL) == -1) \
  	    return err; \
      } \
      else \
*** ../vim-7.3.657/src/version.c	2012-09-05 19:03:51.000000000 +0200
--- src/version.c	2012-09-05 19:07:40.000000000 +0200
***************
*** 721,722 ****
--- 721,724 ----
  {   /* Add new patch number below this line */
+ /**/
+     658,
  /**/

-- 
You know you use Vim too much when you have this alias in your
~/.bashrc file: alias :e=/bin/vim             (Eljay Love-Jensen)

 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///