]>
Commit | Line | Data |
---|---|---|
5a088057 KK |
1 | To: vim_dev@googlegroups.com |
2 | Subject: Patch 7.3.654 | |
3 | Fcc: outbox | |
4 | From: Bram Moolenaar <Bram@moolenaar.net> | |
5 | Mime-Version: 1.0 | |
6 | Content-Type: text/plain; charset=UTF-8 | |
7 | Content-Transfer-Encoding: 8bit | |
8 | ------------ | |
9 | ||
10 | Patch 7.3.654 | |
11 | Problem: When creating a Vim dictionary from Python objects an empty key | |
12 | might be used. | |
13 | Solution: Do not use empty keys, throw an IndexError. (ZyX) | |
14 | Files: src/if_py_both.h | |
15 | ||
16 | ||
17 | *** ../vim-7.3.653/src/if_py_both.h 2012-09-05 17:28:08.000000000 +0200 | |
18 | --- src/if_py_both.h 2012-09-05 18:35:18.000000000 +0200 | |
19 | *************** | |
20 | *** 607,612 **** | |
21 | --- 607,620 ---- | |
22 | ||
23 | static PyTypeObject DictionaryType; | |
24 | ||
25 | + #define DICTKEY_GET_NOTEMPTY(err) \ | |
26 | + DICTKEY_GET(err) \ | |
27 | + if (*key == NUL) \ | |
28 | + { \ | |
29 | + PyErr_SetString(PyExc_ValueError, _("empty keys are not allowed")); \ | |
30 | + return err; \ | |
31 | + } | |
32 | + | |
33 | typedef struct | |
34 | { | |
35 | PyObject_HEAD | |
36 | *************** | |
37 | *** 659,665 **** | |
38 | if (valObject == NULL) | |
39 | return -1; | |
40 | ||
41 | ! DICTKEY_GET(-1) | |
42 | ||
43 | di = dictitem_alloc(key); | |
44 | ||
45 | --- 667,673 ---- | |
46 | if (valObject == NULL) | |
47 | return -1; | |
48 | ||
49 | ! DICTKEY_GET_NOTEMPTY(-1) | |
50 | ||
51 | di = dictitem_alloc(key); | |
52 | ||
53 | *************** | |
54 | *** 730,736 **** | |
55 | return -1; | |
56 | } | |
57 | ||
58 | ! DICTKEY_GET(-1) | |
59 | ||
60 | valObject = PyTuple_GetItem(litem, 1); | |
61 | if (valObject == NULL) | |
62 | --- 738,744 ---- | |
63 | return -1; | |
64 | } | |
65 | ||
66 | ! DICTKEY_GET_NOTEMPTY(-1) | |
67 | ||
68 | valObject = PyTuple_GetItem(litem, 1); | |
69 | if (valObject == NULL) | |
70 | *************** | |
71 | *** 784,799 **** | |
72 | DictionaryItem(PyObject *self, PyObject *keyObject) | |
73 | { | |
74 | char_u *key; | |
75 | ! dictitem_T *val; | |
76 | DICTKEY_DECL | |
77 | ||
78 | ! DICTKEY_GET(NULL) | |
79 | ||
80 | ! val = dict_find(((DictionaryObject *) (self))->dict, key, -1); | |
81 | ||
82 | DICTKEY_UNREF | |
83 | ||
84 | ! return ConvertToPyObject(&val->di_tv); | |
85 | } | |
86 | ||
87 | static PyInt | |
88 | --- 792,813 ---- | |
89 | DictionaryItem(PyObject *self, PyObject *keyObject) | |
90 | { | |
91 | char_u *key; | |
92 | ! dictitem_T *di; | |
93 | DICTKEY_DECL | |
94 | ||
95 | ! DICTKEY_GET_NOTEMPTY(NULL) | |
96 | ! | |
97 | ! di = dict_find(((DictionaryObject *) (self))->dict, key, -1); | |
98 | ||
99 | ! if (di == NULL) | |
100 | ! { | |
101 | ! PyErr_SetString(PyExc_IndexError, _("no such key in dictionary")); | |
102 | ! return NULL; | |
103 | ! } | |
104 | ||
105 | DICTKEY_UNREF | |
106 | ||
107 | ! return ConvertToPyObject(&di->di_tv); | |
108 | } | |
109 | ||
110 | static PyInt | |
111 | *************** | |
112 | *** 811,817 **** | |
113 | return -1; | |
114 | } | |
115 | ||
116 | ! DICTKEY_GET(-1) | |
117 | ||
118 | di = dict_find(d, key, -1); | |
119 | ||
120 | --- 825,831 ---- | |
121 | return -1; | |
122 | } | |
123 | ||
124 | ! DICTKEY_GET_NOTEMPTY(-1) | |
125 | ||
126 | di = dict_find(d, key, -1); | |
127 | ||
128 | *** ../vim-7.3.653/src/version.c 2012-09-05 17:57:34.000000000 +0200 | |
129 | --- src/version.c 2012-09-05 18:38:43.000000000 +0200 | |
130 | *************** | |
131 | *** 721,722 **** | |
132 | --- 721,724 ---- | |
133 | { /* Add new patch number below this line */ | |
134 | + /**/ | |
135 | + 654, | |
136 | /**/ | |
137 | ||
138 | -- | |
139 | MORTICIAN: What? | |
140 | CUSTOMER: Nothing -- here's your nine pence. | |
141 | DEAD PERSON: I'm not dead! | |
142 | MORTICIAN: Here -- he says he's not dead! | |
143 | CUSTOMER: Yes, he is. | |
144 | DEAD PERSON: I'm not! | |
145 | The Quest for the Holy Grail (Monty Python) | |
146 | ||
147 | /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ | |
148 | /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ | |
149 | \\\ an exciting new programming language -- http://www.Zimbu.org /// | |
150 | \\\ help me help AIDS victims -- http://ICCF-Holland.org /// |