python: fix passing size_t values on 64-bit architectures
* lib/python.c (python_proc): Pass a copy of mu_program_name as argv[0]. * python/libmu_py/libmu_py.h (ASSERT_INDEX_RANGE): New macro. * python/libmu_py/address.c: Use Py_ssize_t and check returned value range when getting size_t arguments. * python/libmu_py/auth.c: Likewise. * python/libmu_py/folder.c: Likewise. * python/libmu_py/header.c: Likewise. * python/libmu_py/mailbox.c: Likewise. * python/libmu_py/mailcap.c: Likewise. * python/libmu_py/message.c: Likewise. * python/libmu_py/mime.c: Likewise. * python/libmu_py/secret.c: Likewise. * python/libmu_py/stream.c: Likewise.
Showing
12 changed files
with
103 additions
and
56 deletions
... | @@ -45,8 +45,9 @@ python_proc (mu_script_descr_t descr, mu_message_t msg) | ... | @@ -45,8 +45,9 @@ python_proc (mu_script_descr_t descr, mu_message_t msg) |
45 | mu_py_dict dict[2]; | 45 | mu_py_dict dict[2]; |
46 | mu_py_script_data data[1]; | 46 | mu_py_script_data data[1]; |
47 | char *argv[] = { NULL, NULL }; | 47 | char *argv[] = { NULL, NULL }; |
48 | 48 | char *argv0 = mu_strdup (mu_program_name); | |
49 | argv[0] = mu_program_name; | 49 | |
50 | argv[0] = argv0; | ||
50 | 51 | ||
51 | mu_py_script_init (1, argv); | 52 | mu_py_script_init (1, argv); |
52 | 53 | ||
... | @@ -62,6 +63,9 @@ python_proc (mu_script_descr_t descr, mu_message_t msg) | ... | @@ -62,6 +63,9 @@ python_proc (mu_script_descr_t descr, mu_message_t msg) |
62 | 63 | ||
63 | mu_py_script_run ((char*)descr, data); | 64 | mu_py_script_run ((char*)descr, data); |
64 | mu_py_script_finish (); | 65 | mu_py_script_finish (); |
66 | |||
67 | free (argv0); | ||
68 | |||
65 | return 0; | 69 | return 0; |
66 | } | 70 | } |
67 | 71 | ... | ... |
... | @@ -160,12 +160,15 @@ api_address_destroy (PyObject *self, PyObject *args) | ... | @@ -160,12 +160,15 @@ api_address_destroy (PyObject *self, PyObject *args) |
160 | static PyObject * | 160 | static PyObject * |
161 | api_address_is_group (PyObject *self, PyObject *args) | 161 | api_address_is_group (PyObject *self, PyObject *args) |
162 | { | 162 | { |
163 | int status, n, isgroup; | 163 | int status, isgroup; |
164 | Py_ssize_t n; | ||
164 | PyAddress *py_addr; | 165 | PyAddress *py_addr; |
165 | 166 | ||
166 | if (!PyArg_ParseTuple (args, "O!i", &PyAddressType, &py_addr, &n)) | 167 | if (!PyArg_ParseTuple (args, "O!n", &PyAddressType, &py_addr, &n)) |
167 | return NULL; | 168 | return NULL; |
168 | 169 | ||
170 | ASSERT_INDEX_RANGE (n, "address"); | ||
171 | |||
169 | status = mu_address_is_group (py_addr->addr, n, &isgroup); | 172 | status = mu_address_is_group (py_addr->addr, n, &isgroup); |
170 | return status_object (status, PyBool_FromLong (isgroup)); | 173 | return status_object (status, PyBool_FromLong (isgroup)); |
171 | } | 174 | } |
... | @@ -186,13 +189,16 @@ api_address_get_count (PyObject *self, PyObject *args) | ... | @@ -186,13 +189,16 @@ api_address_get_count (PyObject *self, PyObject *args) |
186 | static PyObject * | 189 | static PyObject * |
187 | api_address_get_email (PyObject *self, PyObject *args) | 190 | api_address_get_email (PyObject *self, PyObject *args) |
188 | { | 191 | { |
189 | int status, n; | 192 | int status; |
193 | Py_ssize_t n; | ||
190 | const char *buf = NULL; | 194 | const char *buf = NULL; |
191 | PyAddress *py_addr; | 195 | PyAddress *py_addr; |
192 | 196 | ||
193 | if (!PyArg_ParseTuple (args, "O!i", &PyAddressType, &py_addr, &n)) | 197 | if (!PyArg_ParseTuple (args, "O!n", &PyAddressType, &py_addr, &n)) |
194 | return NULL; | 198 | return NULL; |
195 | 199 | ||
200 | ASSERT_INDEX_RANGE (n, "address"); | ||
201 | |||
196 | status = mu_address_sget_email (py_addr->addr, n, &buf); | 202 | status = mu_address_sget_email (py_addr->addr, n, &buf); |
197 | return status_object (status, PyString_FromString (buf ? buf : "")); | 203 | return status_object (status, PyString_FromString (buf ? buf : "")); |
198 | } | 204 | } |
... | @@ -200,13 +206,16 @@ api_address_get_email (PyObject *self, PyObject *args) | ... | @@ -200,13 +206,16 @@ api_address_get_email (PyObject *self, PyObject *args) |
200 | static PyObject * | 206 | static PyObject * |
201 | api_address_get_local_part (PyObject *self, PyObject *args) | 207 | api_address_get_local_part (PyObject *self, PyObject *args) |
202 | { | 208 | { |
203 | int status, n; | 209 | int status; |
210 | Py_ssize_t n; | ||
204 | const char *buf = NULL; | 211 | const char *buf = NULL; |
205 | PyAddress *py_addr; | 212 | PyAddress *py_addr; |
206 | 213 | ||
207 | if (!PyArg_ParseTuple (args, "O!i", &PyAddressType, &py_addr, &n)) | 214 | if (!PyArg_ParseTuple (args, "O!n", &PyAddressType, &py_addr, &n)) |
208 | return NULL; | 215 | return NULL; |
209 | 216 | ||
217 | ASSERT_INDEX_RANGE (n, "address part"); | ||
218 | |||
210 | status = mu_address_sget_local_part (py_addr->addr, n, &buf); | 219 | status = mu_address_sget_local_part (py_addr->addr, n, &buf); |
211 | return status_object (status, PyString_FromString (buf ? buf : "")); | 220 | return status_object (status, PyString_FromString (buf ? buf : "")); |
212 | } | 221 | } |
... | @@ -214,13 +223,14 @@ api_address_get_local_part (PyObject *self, PyObject *args) | ... | @@ -214,13 +223,14 @@ api_address_get_local_part (PyObject *self, PyObject *args) |
214 | static PyObject * | 223 | static PyObject * |
215 | api_address_get_domain (PyObject *self, PyObject *args) | 224 | api_address_get_domain (PyObject *self, PyObject *args) |
216 | { | 225 | { |
217 | int status, n; | 226 | int status; |
227 | Py_ssize_t n; | ||
218 | const char *buf = NULL; | 228 | const char *buf = NULL; |
219 | PyAddress *py_addr; | 229 | PyAddress *py_addr; |
220 | 230 | ||
221 | if (!PyArg_ParseTuple (args, "O!i", &PyAddressType, &py_addr, &n)) | 231 | if (!PyArg_ParseTuple (args, "O!n", &PyAddressType, &py_addr, &n)) |
222 | return NULL; | 232 | return NULL; |
223 | 233 | ASSERT_INDEX_RANGE (n, "address part"); | |
224 | status = mu_address_sget_domain (py_addr->addr, n, &buf); | 234 | status = mu_address_sget_domain (py_addr->addr, n, &buf); |
225 | return status_object (status, PyString_FromString (buf ? buf : "")); | 235 | return status_object (status, PyString_FromString (buf ? buf : "")); |
226 | } | 236 | } |
... | @@ -228,13 +238,14 @@ api_address_get_domain (PyObject *self, PyObject *args) | ... | @@ -228,13 +238,14 @@ api_address_get_domain (PyObject *self, PyObject *args) |
228 | static PyObject * | 238 | static PyObject * |
229 | api_address_get_personal (PyObject *self, PyObject *args) | 239 | api_address_get_personal (PyObject *self, PyObject *args) |
230 | { | 240 | { |
231 | int status, n; | 241 | int status; |
242 | Py_ssize_t n; | ||
232 | const char *buf = NULL; | 243 | const char *buf = NULL; |
233 | PyAddress *py_addr; | 244 | PyAddress *py_addr; |
234 | 245 | ||
235 | if (!PyArg_ParseTuple (args, "O!i", &PyAddressType, &py_addr, &n)) | 246 | if (!PyArg_ParseTuple (args, "O!n", &PyAddressType, &py_addr, &n)) |
236 | return NULL; | 247 | return NULL; |
237 | 248 | ASSERT_INDEX_RANGE (n, "address part"); | |
238 | status = mu_address_sget_personal (py_addr->addr, n, &buf); | 249 | status = mu_address_sget_personal (py_addr->addr, n, &buf); |
239 | return status_object (status, PyString_FromString (buf ? buf : "")); | 250 | return status_object (status, PyString_FromString (buf ? buf : "")); |
240 | } | 251 | } |
... | @@ -242,13 +253,14 @@ api_address_get_personal (PyObject *self, PyObject *args) | ... | @@ -242,13 +253,14 @@ api_address_get_personal (PyObject *self, PyObject *args) |
242 | static PyObject * | 253 | static PyObject * |
243 | api_address_get_comments (PyObject *self, PyObject *args) | 254 | api_address_get_comments (PyObject *self, PyObject *args) |
244 | { | 255 | { |
245 | int status, n; | 256 | int status; |
257 | Py_ssize_t n; | ||
246 | const char *buf = NULL; | 258 | const char *buf = NULL; |
247 | PyAddress *py_addr; | 259 | PyAddress *py_addr; |
248 | 260 | ||
249 | if (!PyArg_ParseTuple (args, "O!i", &PyAddressType, &py_addr, &n)) | 261 | if (!PyArg_ParseTuple (args, "O!n", &PyAddressType, &py_addr, &n)) |
250 | return NULL; | 262 | return NULL; |
251 | 263 | ASSERT_INDEX_RANGE (n, "address part"); | |
252 | status = mu_address_sget_comments (py_addr->addr, n, &buf); | 264 | status = mu_address_sget_comments (py_addr->addr, n, &buf); |
253 | return status_object (status, PyString_FromString (buf ? buf : "")); | 265 | return status_object (status, PyString_FromString (buf ? buf : "")); |
254 | } | 266 | } |
... | @@ -256,13 +268,14 @@ api_address_get_comments (PyObject *self, PyObject *args) | ... | @@ -256,13 +268,14 @@ api_address_get_comments (PyObject *self, PyObject *args) |
256 | static PyObject * | 268 | static PyObject * |
257 | api_address_get_route (PyObject *self, PyObject *args) | 269 | api_address_get_route (PyObject *self, PyObject *args) |
258 | { | 270 | { |
259 | int status, n; | 271 | int status; |
272 | Py_ssize_t n; | ||
260 | const char *buf = NULL; | 273 | const char *buf = NULL; |
261 | PyAddress *py_addr; | 274 | PyAddress *py_addr; |
262 | 275 | ||
263 | if (!PyArg_ParseTuple (args, "O!i", &PyAddressType, &py_addr, &n)) | 276 | if (!PyArg_ParseTuple (args, "O!n", &PyAddressType, &py_addr, &n)) |
264 | return NULL; | 277 | return NULL; |
265 | 278 | ASSERT_INDEX_RANGE (n, "address part"); | |
266 | status = mu_address_sget_route (py_addr->addr, n, &buf); | 279 | status = mu_address_sget_route (py_addr->addr, n, &buf); |
267 | return status_object (status, PyString_FromString (buf ? buf : "")); | 280 | return status_object (status, PyString_FromString (buf ? buf : "")); |
268 | } | 281 | } | ... | ... |
... | @@ -591,11 +591,12 @@ static PyObject * | ... | @@ -591,11 +591,12 @@ static PyObject * |
591 | api_get_auth_by_uid (PyObject *self, PyObject *args) | 591 | api_get_auth_by_uid (PyObject *self, PyObject *args) |
592 | { | 592 | { |
593 | uid_t uid; | 593 | uid_t uid; |
594 | Py_ssize_t n; | ||
594 | PyAuthData *py_ad = PyAuthData_NEW (); | 595 | PyAuthData *py_ad = PyAuthData_NEW (); |
595 | 596 | ||
596 | if (!PyArg_ParseTuple (args, "i", &uid)) | 597 | if (!PyArg_ParseTuple (args, "n", &n)) |
597 | return NULL; | 598 | return NULL; |
598 | 599 | uid = (uid_t) n; | |
599 | Py_INCREF (py_ad); | 600 | Py_INCREF (py_ad); |
600 | 601 | ||
601 | py_ad->auth_data = mu_get_auth_by_uid (uid); | 602 | py_ad->auth_data = mu_get_auth_by_uid (uid); | ... | ... |
... | @@ -203,16 +203,20 @@ static PyObject * | ... | @@ -203,16 +203,20 @@ static PyObject * |
203 | api_folder_list (PyObject *self, PyObject *args) | 203 | api_folder_list (PyObject *self, PyObject *args) |
204 | { | 204 | { |
205 | int status = 0; | 205 | int status = 0; |
206 | size_t max_level = 0; | 206 | Py_ssize_t max_level = 0; |
207 | char *dirname, *pattern; | 207 | char *dirname, *pattern; |
208 | PyFolder *py_folder; | 208 | PyFolder *py_folder; |
209 | PyObject *py_list; | 209 | PyObject *py_list; |
210 | mu_list_t c_list = NULL; | 210 | mu_list_t c_list = NULL; |
211 | 211 | ||
212 | if (!PyArg_ParseTuple (args, "O!zs|i", &PyFolderType, &py_folder, | 212 | if (!PyArg_ParseTuple (args, "O!zs|n", &PyFolderType, &py_folder, |
213 | &dirname, &pattern, &max_level)) | 213 | &dirname, &pattern, &max_level)) |
214 | return NULL; | 214 | return NULL; |
215 | 215 | if (max_level < 0) | |
216 | { | ||
217 | PyErr_SetString (PyExc_RuntimeError, "max level out of range"); | ||
218 | return NULL; | ||
219 | } | ||
216 | status = mu_folder_list (py_folder->folder, dirname, pattern, max_level, | 220 | status = mu_folder_list (py_folder->folder, dirname, pattern, max_level, |
217 | &c_list); | 221 | &c_list); |
218 | 222 | ... | ... |
... | @@ -122,14 +122,15 @@ api_header_get_value (PyObject *self, PyObject *args) | ... | @@ -122,14 +122,15 @@ api_header_get_value (PyObject *self, PyObject *args) |
122 | static PyObject * | 122 | static PyObject * |
123 | api_header_get_value_n (PyObject *self, PyObject *args) | 123 | api_header_get_value_n (PyObject *self, PyObject *args) |
124 | { | 124 | { |
125 | int status, n; | 125 | int status; |
126 | Py_ssize_t n; | ||
126 | char *name; | 127 | char *name; |
127 | const char *value = NULL; | 128 | const char *value = NULL; |
128 | PyHeader *py_hdr; | 129 | PyHeader *py_hdr; |
129 | 130 | ||
130 | if (!PyArg_ParseTuple (args, "O!si", &PyHeaderType, &py_hdr, &name, &n)) | 131 | if (!PyArg_ParseTuple (args, "O!sn", &PyHeaderType, &py_hdr, &name, &n)) |
131 | return NULL; | 132 | return NULL; |
132 | 133 | ASSERT_INDEX_RANGE (n, "header"); | |
133 | status = mu_header_sget_value_n (py_hdr->hdr, name, n, &value); | 134 | status = mu_header_sget_value_n (py_hdr->hdr, name, n, &value); |
134 | return status_object (status, PyString_FromString (value ? value : "")); | 135 | return status_object (status, PyString_FromString (value ? value : "")); |
135 | } | 136 | } |
... | @@ -167,13 +168,13 @@ static PyObject * | ... | @@ -167,13 +168,13 @@ static PyObject * |
167 | api_header_get_field_name (PyObject *self, PyObject *args) | 168 | api_header_get_field_name (PyObject *self, PyObject *args) |
168 | { | 169 | { |
169 | int status; | 170 | int status; |
170 | size_t idx; | 171 | Py_ssize_t idx; |
171 | const char *name = NULL; | 172 | const char *name = NULL; |
172 | PyHeader *py_hdr; | 173 | PyHeader *py_hdr; |
173 | 174 | ||
174 | if (!PyArg_ParseTuple (args, "O!i", &PyHeaderType, &py_hdr, &idx)) | 175 | if (!PyArg_ParseTuple (args, "O!n", &PyHeaderType, &py_hdr, &idx)) |
175 | return NULL; | 176 | return NULL; |
176 | 177 | ASSERT_INDEX_RANGE (idx, "header"); | |
177 | status = mu_header_sget_field_name (py_hdr->hdr, idx, &name); | 178 | status = mu_header_sget_field_name (py_hdr->hdr, idx, &name); |
178 | return status_object (status, PyString_FromString (name ? name : "")); | 179 | return status_object (status, PyString_FromString (name ? name : "")); |
179 | } | 180 | } |
... | @@ -182,13 +183,13 @@ static PyObject * | ... | @@ -182,13 +183,13 @@ static PyObject * |
182 | api_header_get_field_value (PyObject *self, PyObject *args) | 183 | api_header_get_field_value (PyObject *self, PyObject *args) |
183 | { | 184 | { |
184 | int status; | 185 | int status; |
185 | size_t idx; | 186 | Py_ssize_t idx; |
186 | const char *value = NULL; | 187 | const char *value = NULL; |
187 | PyHeader *py_hdr; | 188 | PyHeader *py_hdr; |
188 | 189 | ||
189 | if (!PyArg_ParseTuple (args, "O!i", &PyHeaderType, &py_hdr, &idx)) | 190 | if (!PyArg_ParseTuple (args, "O!n", &PyHeaderType, &py_hdr, &idx)) |
190 | return NULL; | 191 | return NULL; |
191 | 192 | ASSERT_INDEX_RANGE (idx, "header"); | |
192 | status = mu_header_sget_field_value (py_hdr->hdr, idx, &value); | 193 | status = mu_header_sget_field_value (py_hdr->hdr, idx, &value); |
193 | return status_object (status, PyString_FromString (value ? value : "")); | 194 | return status_object (status, PyString_FromString (value ? value : "")); |
194 | } | 195 | } | ... | ... |
... | @@ -52,6 +52,17 @@ | ... | @@ -52,6 +52,17 @@ |
52 | #define PY_ROOT_NAME "c_api" | 52 | #define PY_ROOT_NAME "c_api" |
53 | #define PY_PACKAGE_VERSION PACKAGE_VERSION | 53 | #define PY_PACKAGE_VERSION PACKAGE_VERSION |
54 | 54 | ||
55 | #define ASSERT_INDEX_RANGE(n, t) \ | ||
56 | do \ | ||
57 | { \ | ||
58 | if ((n) <= 0) \ | ||
59 | { \ | ||
60 | PyErr_SetString (PyExc_RuntimeError, t " index out of range"); \ | ||
61 | return NULL; \ | ||
62 | } \ | ||
63 | } \ | ||
64 | while (0) | ||
65 | |||
55 | extern inline PyObject * _ro (PyObject *obj); | 66 | extern inline PyObject * _ro (PyObject *obj); |
56 | extern void _py_dealloc (PyObject *self); | 67 | extern void _py_dealloc (PyObject *self); |
57 | extern PyObject * status_object (int status, PyObject *py_obj); | 68 | extern PyObject * status_object (int status, PyObject *py_obj); | ... | ... |
... | @@ -131,7 +131,8 @@ api_mailbox_open (PyObject *self, PyObject *args) | ... | @@ -131,7 +131,8 @@ api_mailbox_open (PyObject *self, PyObject *args) |
131 | 131 | ||
132 | if (!PyArg_ParseTuple (args, "O!i", &PyMailboxType, &py_mbox, &flag)) | 132 | if (!PyArg_ParseTuple (args, "O!i", &PyMailboxType, &py_mbox, &flag)) |
133 | return NULL; | 133 | return NULL; |
134 | 134 | if (!flag) | |
135 | flag = MU_STREAM_READ; | ||
135 | status = mu_mailbox_open (py_mbox->mbox, flag); | 136 | status = mu_mailbox_open (py_mbox->mbox, flag); |
136 | return _ro (PyInt_FromLong (status)); | 137 | return _ro (PyInt_FromLong (status)); |
137 | } | 138 | } |
... | @@ -208,13 +209,15 @@ static PyObject * | ... | @@ -208,13 +209,15 @@ static PyObject * |
208 | api_mailbox_get_message (PyObject *self, PyObject *args) | 209 | api_mailbox_get_message (PyObject *self, PyObject *args) |
209 | { | 210 | { |
210 | int status; | 211 | int status; |
211 | size_t msgno; | 212 | Py_ssize_t msgno; |
212 | PyMailbox *py_mbox; | 213 | PyMailbox *py_mbox; |
213 | PyMessage *py_msg = PyMessage_NEW (); | 214 | PyMessage *py_msg = PyMessage_NEW (); |
214 | 215 | ||
215 | if (!PyArg_ParseTuple (args, "O!i", &PyMailboxType, &py_mbox, &msgno)) | 216 | if (!PyArg_ParseTuple (args, "O!n", &PyMailboxType, &py_mbox, &msgno)) |
216 | return NULL; | 217 | return NULL; |
217 | 218 | ||
219 | ASSERT_INDEX_RANGE (msgno, "message"); | ||
220 | |||
218 | status = mu_mailbox_get_message (py_mbox->mbox, msgno, &py_msg->msg); | 221 | status = mu_mailbox_get_message (py_mbox->mbox, msgno, &py_msg->msg); |
219 | 222 | ||
220 | Py_INCREF (py_msg); | 223 | Py_INCREF (py_msg); | ... | ... |
... | @@ -184,13 +184,14 @@ api_mailcap_entries_count (PyObject *self, PyObject *args) | ... | @@ -184,13 +184,14 @@ api_mailcap_entries_count (PyObject *self, PyObject *args) |
184 | static PyObject * | 184 | static PyObject * |
185 | api_mailcap_get_entry (PyObject *self, PyObject *args) | 185 | api_mailcap_get_entry (PyObject *self, PyObject *args) |
186 | { | 186 | { |
187 | int status, i; | 187 | int status; |
188 | Py_ssize_t i; | ||
188 | PyMailcap *py_mc; | 189 | PyMailcap *py_mc; |
189 | PyMailcapEntry *py_entry = PyMailcapEntry_NEW (); | 190 | PyMailcapEntry *py_entry = PyMailcapEntry_NEW (); |
190 | 191 | ||
191 | if (!PyArg_ParseTuple (args, "O!i", &PyMailcapType, &py_mc, &i)) | 192 | if (!PyArg_ParseTuple (args, "O!n", &PyMailcapType, &py_mc, &i)) |
192 | return NULL; | 193 | return NULL; |
193 | 194 | ASSERT_INDEX_RANGE (i, "mailcap"); | |
194 | status = mu_mailcap_get_entry (py_mc->mc, i, &py_entry->entry); | 195 | status = mu_mailcap_get_entry (py_mc->mc, i, &py_entry->entry); |
195 | 196 | ||
196 | Py_INCREF (py_entry); | 197 | Py_INCREF (py_entry); |
... | @@ -214,14 +215,14 @@ api_mailcap_entry_fields_count (PyObject *self, PyObject *args) | ... | @@ -214,14 +215,14 @@ api_mailcap_entry_fields_count (PyObject *self, PyObject *args) |
214 | static PyObject * | 215 | static PyObject * |
215 | api_mailcap_entry_get_field (PyObject *self, PyObject *args) | 216 | api_mailcap_entry_get_field (PyObject *self, PyObject *args) |
216 | { | 217 | { |
217 | int status, i; | 218 | int status; |
219 | Py_ssize_t i; | ||
218 | char buf[256]; | 220 | char buf[256]; |
219 | PyMailcapEntry *py_entry; | 221 | PyMailcapEntry *py_entry; |
220 | 222 | ||
221 | if (!PyArg_ParseTuple (args, "O!i", &PyMailcapEntryType, &py_entry, | 223 | if (!PyArg_ParseTuple (args, "O!n", &PyMailcapEntryType, &py_entry, &i)) |
222 | &i)) | ||
223 | return NULL; | 224 | return NULL; |
224 | 225 | ASSERT_INDEX_RANGE (i, "mailcap"); | |
225 | status = mu_mailcap_entry_get_field (py_entry->entry, i, buf, | 226 | status = mu_mailcap_entry_get_field (py_entry->entry, i, buf, |
226 | sizeof (buf), NULL); | 227 | sizeof (buf), NULL); |
227 | return status_object (status, PyString_FromString (buf)); | 228 | return status_object (status, PyString_FromString (buf)); | ... | ... |
... | @@ -230,13 +230,13 @@ static PyObject * | ... | @@ -230,13 +230,13 @@ static PyObject * |
230 | api_message_get_part (PyObject *self, PyObject *args) | 230 | api_message_get_part (PyObject *self, PyObject *args) |
231 | { | 231 | { |
232 | int status; | 232 | int status; |
233 | size_t npart; | 233 | Py_ssize_t npart; |
234 | PyMessage *py_msg; | 234 | PyMessage *py_msg; |
235 | PyMessage *py_part = PyMessage_NEW (); | 235 | PyMessage *py_part = PyMessage_NEW (); |
236 | 236 | ||
237 | if (!PyArg_ParseTuple (args, "O!i", &PyMessageType, &py_msg, &npart)) | 237 | if (!PyArg_ParseTuple (args, "O!n", &PyMessageType, &py_msg, &npart)) |
238 | return NULL; | 238 | return NULL; |
239 | 239 | ASSERT_INDEX_RANGE (npart, "message part"); | |
240 | status = mu_message_get_part (py_msg->msg, npart, &py_part->msg); | 240 | status = mu_message_get_part (py_msg->msg, npart, &py_part->msg); |
241 | 241 | ||
242 | Py_INCREF (py_part); | 242 | Py_INCREF (py_part); | ... | ... |
... | @@ -140,13 +140,13 @@ static PyObject * | ... | @@ -140,13 +140,13 @@ static PyObject * |
140 | api_mime_get_part (PyObject *self, PyObject *args) | 140 | api_mime_get_part (PyObject *self, PyObject *args) |
141 | { | 141 | { |
142 | int status; | 142 | int status; |
143 | size_t npart; | 143 | Py_ssize_t npart; |
144 | PyMime *py_mime; | 144 | PyMime *py_mime; |
145 | PyMessage *py_part = PyMessage_NEW (); | 145 | PyMessage *py_part = PyMessage_NEW (); |
146 | 146 | ||
147 | if (!PyArg_ParseTuple (args, "O!i", &PyMimeType, &py_mime, &npart)) | 147 | if (!PyArg_ParseTuple (args, "O!n", &PyMimeType, &py_mime, &npart)) |
148 | return NULL; | 148 | return NULL; |
149 | 149 | ASSERT_INDEX_RANGE (npart, "mime part"); | |
150 | status = mu_mime_get_part (py_mime->mime, npart, &py_part->msg); | 150 | status = mu_mime_get_part (py_mime->mime, npart, &py_part->msg); |
151 | 151 | ||
152 | Py_INCREF (py_part); | 152 | Py_INCREF (py_part); | ... | ... |
... | @@ -87,13 +87,17 @@ api_secret_create (PyObject *self, PyObject *args) | ... | @@ -87,13 +87,17 @@ api_secret_create (PyObject *self, PyObject *args) |
87 | { | 87 | { |
88 | int status; | 88 | int status; |
89 | char *str; | 89 | char *str; |
90 | size_t len; | 90 | Py_ssize_t len; |
91 | PySecret *py_secret; | 91 | PySecret *py_secret; |
92 | 92 | ||
93 | if (!PyArg_ParseTuple (args, "O!si", &PySecretType, &py_secret, | 93 | if (!PyArg_ParseTuple (args, "O!sn", &PySecretType, &py_secret, |
94 | &str, &len)) | 94 | &str, &len)) |
95 | return NULL; | 95 | return NULL; |
96 | 96 | if (len <= 0) | |
97 | { | ||
98 | PyErr_SetString (PyExc_RuntimeError, "secret length out of range"); | ||
99 | return NULL; | ||
100 | } | ||
97 | status = mu_secret_create (&py_secret->secret, str, len); | 101 | status = mu_secret_create (&py_secret->secret, str, len); |
98 | return _ro (PyInt_FromLong (status)); | 102 | return _ro (PyInt_FromLong (status)); |
99 | } | 103 | } | ... | ... |
... | @@ -303,12 +303,17 @@ api_stream_write (PyObject *self, PyObject *args) | ... | @@ -303,12 +303,17 @@ api_stream_write (PyObject *self, PyObject *args) |
303 | { | 303 | { |
304 | int status; | 304 | int status; |
305 | char *wbuf; | 305 | char *wbuf; |
306 | size_t size, write_count; | 306 | Py_ssize_t size; |
307 | size_t write_count; | ||
307 | PyStream *py_stm; | 308 | PyStream *py_stm; |
308 | 309 | ||
309 | if (!PyArg_ParseTuple (args, "O!si", &PyStreamType, &py_stm, &wbuf, &size)) | 310 | if (!PyArg_ParseTuple (args, "O!sn", &PyStreamType, &py_stm, &wbuf, &size)) |
310 | return NULL; | 311 | return NULL; |
311 | 312 | if (size < 0) | |
313 | { | ||
314 | PyErr_SetString (PyExc_RuntimeError, "negative size"); | ||
315 | return NULL; | ||
316 | } | ||
312 | status = mu_stream_write (py_stm->stm, wbuf, size, &write_count); | 317 | status = mu_stream_write (py_stm->stm, wbuf, size, &write_count); |
313 | return status_object (status, PyInt_FromLong (write_count)); | 318 | return status_object (status, PyInt_FromLong (write_count)); |
314 | } | 319 | } | ... | ... |
-
Please register or sign in to post a comment