Karsten Hopp 6a926c
To: vim_dev@googlegroups.com
Karsten Hopp 6a926c
Subject: Patch 7.3.654
Karsten Hopp 6a926c
Fcc: outbox
Karsten Hopp 6a926c
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp 6a926c
Mime-Version: 1.0
Karsten Hopp 6a926c
Content-Type: text/plain; charset=UTF-8
Karsten Hopp 6a926c
Content-Transfer-Encoding: 8bit
Karsten Hopp 6a926c
------------
Karsten Hopp 6a926c
Karsten Hopp 6a926c
Patch 7.3.654
Karsten Hopp 6a926c
Problem:    When creating a Vim dictionary from Python objects an empty key
Karsten Hopp 6a926c
	    might be used.
Karsten Hopp 6a926c
Solution:   Do not use empty keys, throw an IndexError. (ZyX)
Karsten Hopp 6a926c
Files:	    src/if_py_both.h
Karsten Hopp 6a926c
Karsten Hopp 6a926c
Karsten Hopp 6a926c
*** ../vim-7.3.653/src/if_py_both.h	2012-09-05 17:28:08.000000000 +0200
Karsten Hopp 6a926c
--- src/if_py_both.h	2012-09-05 18:35:18.000000000 +0200
Karsten Hopp 6a926c
***************
Karsten Hopp 6a926c
*** 607,612 ****
Karsten Hopp 6a926c
--- 607,620 ----
Karsten Hopp 6a926c
  
Karsten Hopp 6a926c
  static PyTypeObject DictionaryType;
Karsten Hopp 6a926c
  
Karsten Hopp 6a926c
+ #define DICTKEY_GET_NOTEMPTY(err) \
Karsten Hopp 6a926c
+     DICTKEY_GET(err) \
Karsten Hopp 6a926c
+     if (*key == NUL) \
Karsten Hopp 6a926c
+     { \
Karsten Hopp 6a926c
+ 	PyErr_SetString(PyExc_ValueError, _("empty keys are not allowed")); \
Karsten Hopp 6a926c
+ 	return err; \
Karsten Hopp 6a926c
+     }
Karsten Hopp 6a926c
+ 
Karsten Hopp 6a926c
  typedef struct
Karsten Hopp 6a926c
  {
Karsten Hopp 6a926c
      PyObject_HEAD
Karsten Hopp 6a926c
***************
Karsten Hopp 6a926c
*** 659,665 ****
Karsten Hopp 6a926c
  	if (valObject == NULL)
Karsten Hopp 6a926c
  	    return -1;
Karsten Hopp 6a926c
  
Karsten Hopp 6a926c
! 	DICTKEY_GET(-1)
Karsten Hopp 6a926c
  
Karsten Hopp 6a926c
  	di = dictitem_alloc(key);
Karsten Hopp 6a926c
  
Karsten Hopp 6a926c
--- 667,673 ----
Karsten Hopp 6a926c
  	if (valObject == NULL)
Karsten Hopp 6a926c
  	    return -1;
Karsten Hopp 6a926c
  
Karsten Hopp 6a926c
! 	DICTKEY_GET_NOTEMPTY(-1)
Karsten Hopp 6a926c
  
Karsten Hopp 6a926c
  	di = dictitem_alloc(key);
Karsten Hopp 6a926c
  
Karsten Hopp 6a926c
***************
Karsten Hopp 6a926c
*** 730,736 ****
Karsten Hopp 6a926c
  	    return -1;
Karsten Hopp 6a926c
  	}
Karsten Hopp 6a926c
  
Karsten Hopp 6a926c
! 	DICTKEY_GET(-1)
Karsten Hopp 6a926c
  
Karsten Hopp 6a926c
  	valObject = PyTuple_GetItem(litem, 1);
Karsten Hopp 6a926c
  	if (valObject == NULL)
Karsten Hopp 6a926c
--- 738,744 ----
Karsten Hopp 6a926c
  	    return -1;
Karsten Hopp 6a926c
  	}
Karsten Hopp 6a926c
  
Karsten Hopp 6a926c
! 	DICTKEY_GET_NOTEMPTY(-1)
Karsten Hopp 6a926c
  
Karsten Hopp 6a926c
  	valObject = PyTuple_GetItem(litem, 1);
Karsten Hopp 6a926c
  	if (valObject == NULL)
Karsten Hopp 6a926c
***************
Karsten Hopp 6a926c
*** 784,799 ****
Karsten Hopp 6a926c
  DictionaryItem(PyObject *self, PyObject *keyObject)
Karsten Hopp 6a926c
  {
Karsten Hopp 6a926c
      char_u	*key;
Karsten Hopp 6a926c
!     dictitem_T	*val;
Karsten Hopp 6a926c
      DICTKEY_DECL
Karsten Hopp 6a926c
  
Karsten Hopp 6a926c
!     DICTKEY_GET(NULL)
Karsten Hopp 6a926c
  
Karsten Hopp 6a926c
!     val = dict_find(((DictionaryObject *) (self))->dict, key, -1);
Karsten Hopp 6a926c
  
Karsten Hopp 6a926c
      DICTKEY_UNREF
Karsten Hopp 6a926c
  
Karsten Hopp 6a926c
!     return ConvertToPyObject(&val->di_tv);
Karsten Hopp 6a926c
  }
Karsten Hopp 6a926c
  
Karsten Hopp 6a926c
      static PyInt
Karsten Hopp 6a926c
--- 792,813 ----
Karsten Hopp 6a926c
  DictionaryItem(PyObject *self, PyObject *keyObject)
Karsten Hopp 6a926c
  {
Karsten Hopp 6a926c
      char_u	*key;
Karsten Hopp 6a926c
!     dictitem_T	*di;
Karsten Hopp 6a926c
      DICTKEY_DECL
Karsten Hopp 6a926c
  
Karsten Hopp 6a926c
!     DICTKEY_GET_NOTEMPTY(NULL)
Karsten Hopp 6a926c
! 
Karsten Hopp 6a926c
!     di = dict_find(((DictionaryObject *) (self))->dict, key, -1);
Karsten Hopp 6a926c
  
Karsten Hopp 6a926c
!     if (di == NULL)
Karsten Hopp 6a926c
!     {
Karsten Hopp 6a926c
! 	PyErr_SetString(PyExc_IndexError, _("no such key in dictionary"));
Karsten Hopp 6a926c
! 	return NULL;
Karsten Hopp 6a926c
!     }
Karsten Hopp 6a926c
  
Karsten Hopp 6a926c
      DICTKEY_UNREF
Karsten Hopp 6a926c
  
Karsten Hopp 6a926c
!     return ConvertToPyObject(&di->di_tv);
Karsten Hopp 6a926c
  }
Karsten Hopp 6a926c
  
Karsten Hopp 6a926c
      static PyInt
Karsten Hopp 6a926c
***************
Karsten Hopp 6a926c
*** 811,817 ****
Karsten Hopp 6a926c
  	return -1;
Karsten Hopp 6a926c
      }
Karsten Hopp 6a926c
  
Karsten Hopp 6a926c
!     DICTKEY_GET(-1)
Karsten Hopp 6a926c
  
Karsten Hopp 6a926c
      di = dict_find(d, key, -1);
Karsten Hopp 6a926c
  
Karsten Hopp 6a926c
--- 825,831 ----
Karsten Hopp 6a926c
  	return -1;
Karsten Hopp 6a926c
      }
Karsten Hopp 6a926c
  
Karsten Hopp 6a926c
!     DICTKEY_GET_NOTEMPTY(-1)
Karsten Hopp 6a926c
  
Karsten Hopp 6a926c
      di = dict_find(d, key, -1);
Karsten Hopp 6a926c
  
Karsten Hopp 6a926c
*** ../vim-7.3.653/src/version.c	2012-09-05 17:57:34.000000000 +0200
Karsten Hopp 6a926c
--- src/version.c	2012-09-05 18:38:43.000000000 +0200
Karsten Hopp 6a926c
***************
Karsten Hopp 6a926c
*** 721,722 ****
Karsten Hopp 6a926c
--- 721,724 ----
Karsten Hopp 6a926c
  {   /* Add new patch number below this line */
Karsten Hopp 6a926c
+ /**/
Karsten Hopp 6a926c
+     654,
Karsten Hopp 6a926c
  /**/
Karsten Hopp 6a926c
Karsten Hopp 6a926c
-- 
Karsten Hopp 6a926c
MORTICIAN:    What?
Karsten Hopp 6a926c
CUSTOMER:     Nothing -- here's your nine pence.
Karsten Hopp 6a926c
DEAD PERSON:  I'm not dead!
Karsten Hopp 6a926c
MORTICIAN:    Here -- he says he's not dead!
Karsten Hopp 6a926c
CUSTOMER:     Yes, he is.
Karsten Hopp 6a926c
DEAD PERSON:  I'm not!
Karsten Hopp 6a926c
                                  The Quest for the Holy Grail (Monty Python)
Karsten Hopp 6a926c
Karsten Hopp 6a926c
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp 6a926c
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp 6a926c
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
Karsten Hopp 6a926c
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///