Skip to content

Commit

Permalink
updated for version 7.3.654
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
brammool committed Sep 5, 2012
1 parent 15ffbeb commit 817a4b1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/if_py_both.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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);

Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
654,
/**/
653,
/**/
Expand Down

0 comments on commit 817a4b1

Please sign in to comment.