To: vim_dev@googlegroups.com
Subject: Patch 7.3.654
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.654
Problem:    When creating a Vim dictionary from Python objects an empty key
	    might be used.
Solution:   Do not use empty keys, throw an IndexError. (ZyX)
Files:	    src/if_py_both.h


*** ../vim-7.3.653/src/if_py_both.h	2012-09-05 17:28:08.000000000 +0200
--- src/if_py_both.h	2012-09-05 18:35:18.000000000 +0200
***************
*** 607,612 ****
--- 607,620 ----
  
  static PyTypeObject DictionaryType;
  
+ #define DICTKEY_GET_NOTEMPTY(err) \
+     DICTKEY_GET(err) \
+     if (*key == NUL) \
+     { \
+ 	PyErr_SetString(PyExc_ValueError, _("empty keys are not allowed")); \
+ 	return err; \
+     }
+ 
  typedef struct
  {
      PyObject_HEAD
***************
*** 659,665 ****
  	if (valObject == NULL)
  	    return -1;
  
! 	DICTKEY_GET(-1)
  
  	di = dictitem_alloc(key);
  
--- 667,673 ----
  	if (valObject == NULL)
  	    return -1;
  
! 	DICTKEY_GET_NOTEMPTY(-1)
  
  	di = dictitem_alloc(key);
  
***************
*** 730,736 ****
  	    return -1;
  	}
  
! 	DICTKEY_GET(-1)
  
  	valObject = PyTuple_GetItem(litem, 1);
  	if (valObject == NULL)
--- 738,744 ----
  	    return -1;
  	}
  
! 	DICTKEY_GET_NOTEMPTY(-1)
  
  	valObject = PyTuple_GetItem(litem, 1);
  	if (valObject == NULL)
***************
*** 784,799 ****
  DictionaryItem(PyObject *self, PyObject *keyObject)
  {
      char_u	*key;
!     dictitem_T	*val;
      DICTKEY_DECL
  
!     DICTKEY_GET(NULL)
  
!     val = dict_find(((DictionaryObject *) (self))->dict, key, -1);
  
      DICTKEY_UNREF
  
!     return ConvertToPyObject(&val->di_tv);
  }
  
      static PyInt
--- 792,813 ----
  DictionaryItem(PyObject *self, PyObject *keyObject)
  {
      char_u	*key;
!     dictitem_T	*di;
      DICTKEY_DECL
  
!     DICTKEY_GET_NOTEMPTY(NULL)
! 
!     di = dict_find(((DictionaryObject *) (self))->dict, key, -1);
  
!     if (di == NULL)
!     {
! 	PyErr_SetString(PyExc_IndexError, _("no such key in dictionary"));
! 	return NULL;
!     }
  
      DICTKEY_UNREF
  
!     return ConvertToPyObject(&di->di_tv);
  }
  
      static PyInt
***************
*** 811,817 ****
  	return -1;
      }
  
!     DICTKEY_GET(-1)
  
      di = dict_find(d, key, -1);
  
--- 825,831 ----
  	return -1;
      }
  
!     DICTKEY_GET_NOTEMPTY(-1)
  
      di = dict_find(d, key, -1);
  
*** ../vim-7.3.653/src/version.c	2012-09-05 17:57:34.000000000 +0200
--- src/version.c	2012-09-05 18:38:43.000000000 +0200
***************
*** 721,722 ****
--- 721,724 ----
  {   /* Add new patch number below this line */
+ /**/
+     654,
  /**/

-- 
MORTICIAN:    What?
CUSTOMER:     Nothing -- here's your nine pence.
DEAD PERSON:  I'm not dead!
MORTICIAN:    Here -- he says he's not dead!
CUSTOMER:     Yes, he is.
DEAD PERSON:  I'm not!
                                  The Quest for the Holy Grail (Monty Python)

 /// 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    ///
