summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2012-09-05 18:45:28 +0200
committerBram Moolenaar <Bram@vim.org>2012-09-05 18:45:28 +0200
commit231e1a17232a6d396266194efad53259e7d05ff1 (patch)
tree4d0678578207560effa5b0d1682888eb5dfb4d1b
parente2db4361d2236b1bf56fb436d274c8b9b361196c (diff)
updated for version 7.3.654v7.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)
-rw-r--r--src/if_py_both.h28
-rw-r--r--src/version.c2
2 files changed, 23 insertions, 7 deletions
diff --git a/src/if_py_both.h b/src/if_py_both.h
index 931ecb98a7..3ab18516eb 100644
--- a/src/if_py_both.h
+++ b/src/if_py_both.h
@@ -607,6 +607,14 @@ pyll_add(PyObject *self, pylinkedlist_T *ref, pylinkedlist_T **last)
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,7 +667,7 @@ pydict_to_tv(PyObject *obj, typval_T *tv, PyObject *lookupDict)
if (valObject == NULL)
return -1;
- DICTKEY_GET(-1)
+ DICTKEY_GET_NOTEMPTY(-1)
di = dictitem_alloc(key);
@@ -730,7 +738,7 @@ pymap_to_tv(PyObject *obj, typval_T *tv, PyObject *lookupDict)
return -1;
}
- DICTKEY_GET(-1)
+ DICTKEY_GET_NOTEMPTY(-1)
valObject = PyTuple_GetItem(litem, 1);
if (valObject == NULL)
@@ -784,16 +792,22 @@ DictionaryLength(PyObject *self)
DictionaryItem(PyObject *self, PyObject *keyObject)
{
char_u *key;
- dictitem_T *val;
+ dictitem_T *di;
DICTKEY_DECL
- DICTKEY_GET(NULL)
+ DICTKEY_GET_NOTEMPTY(NULL)
+
+ di = dict_find(((DictionaryObject *) (self))->dict, key, -1);
- val = 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(&val->di_tv);
+ return ConvertToPyObject(&di->di_tv);
}
static PyInt
@@ -811,7 +825,7 @@ DictionaryAssItem(PyObject *self, PyObject *keyObject, PyObject *valObject)
return -1;
}
- DICTKEY_GET(-1)
+ DICTKEY_GET_NOTEMPTY(-1)
di = dict_find(d, key, -1);
diff --git a/src/version.c b/src/version.c
index 4c31c9761f..b3daa7d61c 100644
--- a/src/version.c
+++ b/src/version.c
@@ -720,6 +720,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 654,
+/**/
653,
/**/
652,