commit-mailutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[SCM] GNU Mailutils branch, master, updated. release-2.2-715-g1236f0a


From: Sergey Poznyakoff
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-715-g1236f0a
Date: Sat, 27 Jun 2015 08:34:52 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU Mailutils".

http://git.savannah.gnu.org/cgit/mailutils.git/commit/?id=1236f0ab24b50e76da6554c305dedda8a1e6d8bb

The branch, master has been updated
       via  1236f0ab24b50e76da6554c305dedda8a1e6d8bb (commit)
       via  37944b1184319def0eee6cb9ba50dfeb476f7301 (commit)
      from  a551d489683e8b3a2849580f1672825a611927c9 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 1236f0ab24b50e76da6554c305dedda8a1e6d8bb
Author: Sergey Poznyakoff <address@hidden>
Date:   Sat Jun 27 11:20:31 2015 +0300

    python: fix returning size_t values.
    
    * python/libmu_py/address.c: Use PyInt_FromSize_t to return size_t
    and similar values.
    * python/libmu_py/auth.c: Likewise.
    * python/libmu_py/body.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/sieve.c: Likewise.
    * python/libmu_py/stream.c: Likewise.

commit 37944b1184319def0eee6cb9ba50dfeb476f7301
Author: Sergey Poznyakoff <address@hidden>
Date:   Sat Jun 27 10:57:42 2015 +0300

    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.

-----------------------------------------------------------------------

Summary of changes:
 lib/python.c               |    8 +++++-
 python/libmu_py/address.c  |   51 ++++++++++++++++++++++++++---------------
 python/libmu_py/auth.c     |   53 ++++++++++++++++++++------------------------
 python/libmu_py/body.c     |    4 +-
 python/libmu_py/folder.c   |   10 +++++--
 python/libmu_py/header.c   |   25 ++++++++++----------
 python/libmu_py/libmu_py.h |   11 +++++++++
 python/libmu_py/mailbox.c  |   21 ++++++++++------
 python/libmu_py/mailcap.c  |   19 ++++++++-------
 python/libmu_py/message.c  |   14 +++++-----
 python/libmu_py/mime.c     |    8 +++---
 python/libmu_py/secret.c   |   10 +++++--
 python/libmu_py/sieve.c    |    2 +-
 python/libmu_py/stream.c   |   17 +++++++++-----
 14 files changed, 148 insertions(+), 105 deletions(-)

diff --git a/lib/python.c b/lib/python.c
index 7fb32ee..7120326 100644
--- a/lib/python.c
+++ b/lib/python.c
@@ -45,8 +45,9 @@ python_proc (mu_script_descr_t descr, mu_message_t msg)
   mu_py_dict dict[2];
   mu_py_script_data data[1];
   char *argv[] = { NULL, NULL };
-
-  argv[0] = mu_program_name;
+  char *argv0 = mu_strdup (mu_program_name);
+  
+  argv[0] = argv0;
   
   mu_py_script_init (1, argv);
 
@@ -62,6 +63,9 @@ python_proc (mu_script_descr_t descr, mu_message_t msg)
 
   mu_py_script_run ((char*)descr, data);
   mu_py_script_finish ();
+
+  free (argv0);
+  
   return 0;
 }
 
diff --git a/python/libmu_py/address.c b/python/libmu_py/address.c
index f6f487a..9cc56d7 100644
--- a/python/libmu_py/address.c
+++ b/python/libmu_py/address.c
@@ -160,12 +160,15 @@ api_address_destroy (PyObject *self, PyObject *args)
 static PyObject *
 api_address_is_group (PyObject *self, PyObject *args)
 {
-  int status, n, isgroup;
+  int status, isgroup;
+  Py_ssize_t n;
   PyAddress *py_addr;
 
-  if (!PyArg_ParseTuple (args, "O!i", &PyAddressType, &py_addr, &n))
+  if (!PyArg_ParseTuple (args, "O!n", &PyAddressType, &py_addr, &n))
     return NULL;
 
+  ASSERT_INDEX_RANGE (n, "address");
+
   status = mu_address_is_group (py_addr->addr, n, &isgroup);
   return status_object (status, PyBool_FromLong (isgroup));
 }
@@ -180,19 +183,22 @@ api_address_get_count (PyObject *self, PyObject *args)
     return NULL;
 
   mu_address_get_count (py_addr->addr, &count);
-  return _ro (PyInt_FromLong (count));
+  return _ro (PyInt_FromSize_t (count));
 }
 
 static PyObject *
 api_address_get_email (PyObject *self, PyObject *args)
 {
-  int status, n;
+  int status;
+  Py_ssize_t n;
   const char *buf = NULL;
   PyAddress *py_addr;
 
-  if (!PyArg_ParseTuple (args, "O!i", &PyAddressType, &py_addr, &n))
+  if (!PyArg_ParseTuple (args, "O!n", &PyAddressType, &py_addr, &n))
     return NULL;
 
+  ASSERT_INDEX_RANGE (n, "address");
+  
   status = mu_address_sget_email (py_addr->addr, n, &buf);
   return status_object (status, PyString_FromString (buf ? buf : ""));
 }
@@ -200,13 +206,16 @@ api_address_get_email (PyObject *self, PyObject *args)
 static PyObject *
 api_address_get_local_part (PyObject *self, PyObject *args)
 {
-  int status, n;
+  int status;
+  Py_ssize_t n;
   const char *buf = NULL;
   PyAddress *py_addr;
 
-  if (!PyArg_ParseTuple (args, "O!i", &PyAddressType, &py_addr, &n))
+  if (!PyArg_ParseTuple (args, "O!n", &PyAddressType, &py_addr, &n))
     return NULL;
 
+  ASSERT_INDEX_RANGE (n, "address part");
+
   status = mu_address_sget_local_part (py_addr->addr, n, &buf);
   return status_object (status, PyString_FromString (buf ? buf : ""));
 }
@@ -214,13 +223,14 @@ api_address_get_local_part (PyObject *self, PyObject 
*args)
 static PyObject *
 api_address_get_domain (PyObject *self, PyObject *args)
 {
-  int status, n;
+  int status;
+  Py_ssize_t n;
   const char *buf = NULL;
   PyAddress *py_addr;
 
-  if (!PyArg_ParseTuple (args, "O!i", &PyAddressType, &py_addr, &n))
+  if (!PyArg_ParseTuple (args, "O!n", &PyAddressType, &py_addr, &n))
     return NULL;
-
+  ASSERT_INDEX_RANGE (n, "address part");
   status = mu_address_sget_domain (py_addr->addr, n, &buf);
   return status_object (status, PyString_FromString (buf ? buf : ""));
 }
@@ -228,13 +238,14 @@ api_address_get_domain (PyObject *self, PyObject *args)
 static PyObject *
 api_address_get_personal (PyObject *self, PyObject *args)
 {
-  int status, n;
+  int status;
+  Py_ssize_t n;
   const char *buf = NULL;
   PyAddress *py_addr;
 
-  if (!PyArg_ParseTuple (args, "O!i", &PyAddressType, &py_addr, &n))
+  if (!PyArg_ParseTuple (args, "O!n", &PyAddressType, &py_addr, &n))
     return NULL;
-
+  ASSERT_INDEX_RANGE (n,  "address part");
   status = mu_address_sget_personal (py_addr->addr, n, &buf);
   return status_object (status, PyString_FromString (buf ? buf : ""));
 }
@@ -242,13 +253,14 @@ api_address_get_personal (PyObject *self, PyObject *args)
 static PyObject *
 api_address_get_comments (PyObject *self, PyObject *args)
 {
-  int status, n;
+  int status;
+  Py_ssize_t n;
   const char *buf = NULL;
   PyAddress *py_addr;
 
-  if (!PyArg_ParseTuple (args, "O!i", &PyAddressType, &py_addr, &n))
+  if (!PyArg_ParseTuple (args, "O!n", &PyAddressType, &py_addr, &n))
     return NULL;
-
+  ASSERT_INDEX_RANGE (n, "address part");
   status = mu_address_sget_comments (py_addr->addr, n, &buf);
   return status_object (status, PyString_FromString (buf ? buf : ""));
 }
@@ -256,13 +268,14 @@ api_address_get_comments (PyObject *self, PyObject *args)
 static PyObject *
 api_address_get_route (PyObject *self, PyObject *args)
 {
-  int status, n;
+  int status;
+  Py_ssize_t n;
   const char *buf = NULL;
   PyAddress *py_addr;
 
-  if (!PyArg_ParseTuple (args, "O!i", &PyAddressType, &py_addr, &n))
+  if (!PyArg_ParseTuple (args, "O!n", &PyAddressType, &py_addr, &n))
     return NULL;
-
+  ASSERT_INDEX_RANGE (n, "address part");
   status = mu_address_sget_route (py_addr->addr, n, &buf);
   return status_object (status, PyString_FromString (buf ? buf : ""));
 }
diff --git a/python/libmu_py/auth.c b/python/libmu_py/auth.c
index 52e8f80..921cee0 100644
--- a/python/libmu_py/auth.c
+++ b/python/libmu_py/auth.c
@@ -201,42 +201,36 @@ _getattr4 (PyObject *self, char *name)
   if (!ad)
     return NULL;
 
-  if (strcmp (name, "name") == 0) {
+  if (strcmp (name, "name") == 0)
     return PyString_FromString (ad->name);
-  }
-  else if (strcmp (name, "passwd") == 0) {
+  else if (strcmp (name, "passwd") == 0)
     return PyString_FromString (ad->passwd);
-  }
-  else if (strcmp (name, "uid") == 0) {
-    return PyInt_FromLong (ad->uid);
-  }
-  else if (strcmp (name, "gid") == 0) {
-    return PyInt_FromLong (ad->gid);
-  }
-  else if (strcmp (name, "gecos") == 0) {
+
+  /* FIXME: The use of PyInt_FromSize_t to convert uid_t and gid_t is
+     a bit dubious, but so far there's no other feasible way in Python,
+     save for converting uid (gid) to string and using PyInt_FromString. */
+  else if (strcmp (name, "uid") == 0)
+    return PyInt_FromSize_t (ad->uid);
+  else if (strcmp (name, "gid") == 0)
+    return PyInt_FromSize_t (ad->gid);
+  else if (strcmp (name, "gecos") == 0)
     return PyString_FromString (ad->gecos);
-  }
-  else if (strcmp (name, "dir") == 0) {
+  else if (strcmp (name, "dir") == 0)
     return PyString_FromString (ad->dir);
-  }
-  else if (strcmp (name, "shell") == 0) {
+  else if (strcmp (name, "shell") == 0)
     return PyString_FromString (ad->shell);
-  }
-  else if (strcmp (name, "mailbox") == 0) {
+  else if (strcmp (name, "mailbox") == 0)
     return PyString_FromString (ad->mailbox);
-  }
-  else if (strcmp (name, "source") == 0) {
+  else if (strcmp (name, "source") == 0)
     return PyString_FromString (ad->source);
-  }
-  else if (strcmp (name, "quota") == 0) {
-    return PyInt_FromLong (ad->quota);
-  }
-  else if (strcmp (name, "flags") == 0) {
+  else if (strcmp (name, "quota") == 0)
+    /* FIXME: quota is mu_off_t rather than size_t.  See comment for uid
+       above */
+    return PyInt_FromSize_t (ad->quota);
+  else if (strcmp (name, "flags") == 0)
     return PyInt_FromLong (ad->flags);
-  }
-  else if (strcmp (name, "change_uid") == 0) {
+  else if (strcmp (name, "change_uid") == 0)
     return PyInt_FromLong (ad->change_uid);
-  }
   return NULL;
 }
 
@@ -591,11 +585,12 @@ static PyObject *
 api_get_auth_by_uid (PyObject *self, PyObject *args)
 {
   uid_t uid;
+  Py_ssize_t n;
   PyAuthData *py_ad = PyAuthData_NEW ();
 
-  if (!PyArg_ParseTuple (args, "i", &uid))
+  if (!PyArg_ParseTuple (args, "n", &n))
     return NULL;
-
+  uid = (uid_t) n;
   Py_INCREF (py_ad);
 
   py_ad->auth_data = mu_get_auth_by_uid (uid);
diff --git a/python/libmu_py/body.c b/python/libmu_py/body.c
index 214bc6a..dcd41bd 100644
--- a/python/libmu_py/body.c
+++ b/python/libmu_py/body.c
@@ -87,7 +87,7 @@ api_body_size (PyObject *self, PyObject *args)
     return NULL;
 
   status = mu_body_size (py_body->body, &size);
-  return status_object (status, PyInt_FromLong (size));
+  return status_object (status, PyInt_FromSize_t (size));
 }
 
 static PyObject *
@@ -101,7 +101,7 @@ api_body_lines (PyObject *self, PyObject *args)
     return NULL;
 
   status = mu_body_lines (py_body->body, &lines);
-  return status_object (status, PyInt_FromLong (lines));
+  return status_object (status, PyInt_FromSize_t (lines));
 }
 
 static PyObject *
diff --git a/python/libmu_py/folder.c b/python/libmu_py/folder.c
index dfd9def..5fe2967 100644
--- a/python/libmu_py/folder.c
+++ b/python/libmu_py/folder.c
@@ -203,16 +203,20 @@ static PyObject *
 api_folder_list (PyObject *self, PyObject *args)
 {
   int status = 0;
-  size_t max_level = 0;
+  Py_ssize_t max_level = 0;
   char *dirname, *pattern;
   PyFolder *py_folder;
   PyObject *py_list;
   mu_list_t c_list = NULL;
 
-  if (!PyArg_ParseTuple (args, "O!zs|i", &PyFolderType, &py_folder,
+  if (!PyArg_ParseTuple (args, "O!zs|n", &PyFolderType, &py_folder,
                         &dirname, &pattern, &max_level))
     return NULL;
-
+  if (max_level < 0)
+    {
+      PyErr_SetString (PyExc_RuntimeError, "max level out of range");
+      return NULL;
+    }
   status = mu_folder_list (py_folder->folder, dirname, pattern, max_level,
                           &c_list);
 
diff --git a/python/libmu_py/header.c b/python/libmu_py/header.c
index d64d15d..3711193 100644
--- a/python/libmu_py/header.c
+++ b/python/libmu_py/header.c
@@ -87,7 +87,7 @@ api_header_size (PyObject *self, PyObject *args)
     return NULL;
 
   status = mu_header_size (py_hdr->hdr, &size);
-  return status_object (status, PyInt_FromLong (size));
+  return status_object (status, PyInt_FromSize_t (size));
 }
 
 static PyObject *
@@ -101,7 +101,7 @@ api_header_lines (PyObject *self, PyObject *args)
     return NULL;
 
   status = mu_header_lines (py_hdr->hdr, &lines);
-  return status_object (status, PyInt_FromLong (lines));
+  return status_object (status, PyInt_FromSize_t (lines));
 }
 
 static PyObject *
@@ -122,14 +122,15 @@ api_header_get_value (PyObject *self, PyObject *args)
 static PyObject *
 api_header_get_value_n (PyObject *self, PyObject *args)
 {
-  int status, n;
+  int status;
+  Py_ssize_t n;
   char *name;
   const char *value = NULL;
   PyHeader *py_hdr;
 
-  if (!PyArg_ParseTuple (args, "O!si", &PyHeaderType, &py_hdr, &name, &n))
+  if (!PyArg_ParseTuple (args, "O!sn", &PyHeaderType, &py_hdr, &name, &n))
     return NULL;
-
+  ASSERT_INDEX_RANGE (n, "header");
   status = mu_header_sget_value_n (py_hdr->hdr, name, n, &value);
   return status_object (status, PyString_FromString (value ? value : ""));
 }
@@ -160,20 +161,20 @@ api_header_get_field_count (PyObject *self, PyObject 
*args)
     return NULL;
 
   status = mu_header_get_field_count (py_hdr->hdr, &count);
-  return status_object (status, PyInt_FromLong (count));
+  return status_object (status, PyInt_FromSize_t (count));
 }
 
 static PyObject *
 api_header_get_field_name (PyObject *self, PyObject *args)
 {
   int status;
-  size_t idx;
+  Py_ssize_t idx;
   const char *name = NULL;
   PyHeader *py_hdr;
 
-  if (!PyArg_ParseTuple (args, "O!i", &PyHeaderType, &py_hdr, &idx))
+  if (!PyArg_ParseTuple (args, "O!n", &PyHeaderType, &py_hdr, &idx))
     return NULL;
-
+  ASSERT_INDEX_RANGE (idx, "header");
   status = mu_header_sget_field_name (py_hdr->hdr, idx, &name);
   return status_object (status, PyString_FromString (name ? name : ""));
 }
@@ -182,13 +183,13 @@ static PyObject *
 api_header_get_field_value (PyObject *self, PyObject *args)
 {
   int status;
-  size_t idx;
+  Py_ssize_t idx;
   const char *value = NULL;
   PyHeader *py_hdr;
 
-  if (!PyArg_ParseTuple (args, "O!i", &PyHeaderType, &py_hdr, &idx))
+  if (!PyArg_ParseTuple (args, "O!n", &PyHeaderType, &py_hdr, &idx))
     return NULL;
-
+  ASSERT_INDEX_RANGE (idx, "header");
   status = mu_header_sget_field_value (py_hdr->hdr, idx, &value);
   return status_object (status, PyString_FromString (value ? value : ""));
 }
diff --git a/python/libmu_py/libmu_py.h b/python/libmu_py/libmu_py.h
index 7464033..9798527 100644
--- a/python/libmu_py/libmu_py.h
+++ b/python/libmu_py/libmu_py.h
@@ -52,6 +52,17 @@
 #define PY_ROOT_NAME "c_api"
 #define PY_PACKAGE_VERSION PACKAGE_VERSION
 
+#define ASSERT_INDEX_RANGE(n, t)                                        \
+  do                                                                    \
+    {                                                                   \
+      if ((n) <= 0)                                                     \
+       {                                                                \
+          PyErr_SetString (PyExc_RuntimeError, t " index out of range"); \
+          return NULL;                                                  \
+       }                                                                \
+    }                                                                   \
+  while (0)
+
 extern inline PyObject * _ro (PyObject *obj);
 extern void _py_dealloc (PyObject *self);
 extern PyObject * status_object (int status, PyObject *py_obj);
diff --git a/python/libmu_py/mailbox.c b/python/libmu_py/mailbox.c
index 958f176..013ad6f 100644
--- a/python/libmu_py/mailbox.c
+++ b/python/libmu_py/mailbox.c
@@ -131,7 +131,8 @@ api_mailbox_open (PyObject *self, PyObject *args)
 
   if (!PyArg_ParseTuple (args, "O!i", &PyMailboxType, &py_mbox, &flag))
     return NULL;
-
+  if (!flag)
+    flag = MU_STREAM_READ;
   status = mu_mailbox_open (py_mbox->mbox, flag);
   return _ro (PyInt_FromLong (status));
 }
@@ -173,7 +174,7 @@ api_mailbox_messages_count (PyObject *self, PyObject *args)
     return NULL;
 
   status = mu_mailbox_messages_count (py_mbox->mbox, &total);
-  return status_object (status, PyInt_FromLong (total));
+  return status_object (status, PyInt_FromSize_t (total));
 }
 
 static PyObject *
@@ -187,7 +188,7 @@ api_mailbox_messages_recent (PyObject *self, PyObject *args)
     return NULL;
 
   status = mu_mailbox_messages_recent (py_mbox->mbox, &recent);
-  return status_object (status, PyInt_FromLong (recent));
+  return status_object (status, PyInt_FromSize_t (recent));
 }
 
 static PyObject *
@@ -201,20 +202,22 @@ api_mailbox_message_unseen (PyObject *self, PyObject 
*args)
     return NULL;
 
   status = mu_mailbox_message_unseen (py_mbox->mbox, &unseen);
-  return status_object (status, PyInt_FromLong (unseen));
+  return status_object (status, PyInt_FromSize_t (unseen));
 }
 
 static PyObject *
 api_mailbox_get_message (PyObject *self, PyObject *args)
 {
   int status;
-  size_t msgno;
+  Py_ssize_t msgno;
   PyMailbox *py_mbox;
   PyMessage *py_msg = PyMessage_NEW ();
 
-  if (!PyArg_ParseTuple (args, "O!i", &PyMailboxType, &py_mbox, &msgno))
+  if (!PyArg_ParseTuple (args, "O!n", &PyMailboxType, &py_mbox, &msgno))
     return NULL;
 
+  ASSERT_INDEX_RANGE (msgno, "message");
+  
   status = mu_mailbox_get_message (py_mbox->mbox, msgno, &py_msg->msg);
 
   Py_INCREF (py_msg);
@@ -273,7 +276,7 @@ uidls_extractor (void *data, PyObject **dst)
   struct mu_uidl *uidl = (struct mu_uidl *)data;
 
   *dst = PyTuple_New (2);
-  PyTuple_SetItem (*dst, 0, PyInt_FromLong (uidl->msgno));
+  PyTuple_SetItem (*dst, 0, PyInt_FromSize_t (uidl->msgno));
   PyTuple_SetItem (*dst, 1, PyString_FromString (uidl->uidl));
   return 0;
 }
@@ -336,7 +339,9 @@ api_mailbox_get_size (PyObject *self, PyObject *args)
     return NULL;
 
   status = mu_mailbox_get_size (py_mbox->mbox, &size);
-  return status_object (status, PyInt_FromLong (size));
+  /* FIXME: Using PyInt_FromSize_t to convert mu_off_t can cause truncation
+     for very large mailboxes. */
+  return status_object (status, PyInt_FromSize_t (size));
 }
 
 static PyObject *
diff --git a/python/libmu_py/mailcap.c b/python/libmu_py/mailcap.c
index 4366ef2..a000345 100644
--- a/python/libmu_py/mailcap.c
+++ b/python/libmu_py/mailcap.c
@@ -178,19 +178,20 @@ api_mailcap_entries_count (PyObject *self, PyObject *args)
     return NULL;
 
   status = mu_mailcap_entries_count (py_mc->mc, &count);
-  return status_object (status, PyInt_FromLong (count));
+  return status_object (status, PyInt_FromSize_t (count));
 }
 
 static PyObject *
 api_mailcap_get_entry (PyObject *self, PyObject *args)
 {
-  int status, i;
+  int status;
+  Py_ssize_t i;
   PyMailcap *py_mc;
   PyMailcapEntry *py_entry = PyMailcapEntry_NEW ();
 
-  if (!PyArg_ParseTuple (args, "O!i", &PyMailcapType, &py_mc, &i))
+  if (!PyArg_ParseTuple (args, "O!n", &PyMailcapType, &py_mc, &i))
     return NULL;
-
+  ASSERT_INDEX_RANGE (i, "mailcap");
   status = mu_mailcap_get_entry (py_mc->mc, i, &py_entry->entry);
 
   Py_INCREF (py_entry);
@@ -208,20 +209,20 @@ api_mailcap_entry_fields_count (PyObject *self, PyObject 
*args)
     return NULL;
 
   status = mu_mailcap_entry_fields_count (py_entry->entry, &count);
-  return status_object (status, PyInt_FromLong (count));
+  return status_object (status, PyInt_FromSize_t (count));
 }
 
 static PyObject *
 api_mailcap_entry_get_field (PyObject *self, PyObject *args)
 {
-  int status, i;
+  int status;
+  Py_ssize_t i;
   char buf[256];
   PyMailcapEntry *py_entry;
 
-  if (!PyArg_ParseTuple (args, "O!i", &PyMailcapEntryType, &py_entry,
-                        &i))
+  if (!PyArg_ParseTuple (args, "O!n", &PyMailcapEntryType, &py_entry, &i))
     return NULL;
-
+  ASSERT_INDEX_RANGE (i, "mailcap");
   status = mu_mailcap_entry_get_field (py_entry->entry, i, buf,
                                       sizeof (buf), NULL);
   return status_object (status, PyString_FromString (buf));
diff --git a/python/libmu_py/message.c b/python/libmu_py/message.c
index 61a55ec..3ae5d84 100644
--- a/python/libmu_py/message.c
+++ b/python/libmu_py/message.c
@@ -131,7 +131,7 @@ api_message_size (PyObject *self, PyObject *args)
     return NULL;
 
   status = mu_message_size (py_msg->msg, &size);
-  return status_object (status, PyInt_FromLong (size));
+  return status_object (status, PyInt_FromSize_t (size));
 }
 
 static PyObject *
@@ -145,7 +145,7 @@ api_message_lines (PyObject *self, PyObject *args)
     return NULL;
 
   status = mu_message_lines (py_msg->msg, &lines);
-  return status_object (status, PyInt_FromLong (lines));
+  return status_object (status, PyInt_FromSize_t (lines));
 }
 
 static PyObject *
@@ -223,20 +223,20 @@ api_message_get_num_parts (PyObject *self, PyObject *args)
     return NULL;
 
   status = mu_message_get_num_parts (py_msg->msg, &parts);
-  return status_object (status, PyInt_FromLong (parts));
+  return status_object (status, PyInt_FromSize_t (parts));
 }
 
 static PyObject *
 api_message_get_part (PyObject *self, PyObject *args)
 {
   int status;
-  size_t npart;
+  Py_ssize_t npart;
   PyMessage *py_msg;
   PyMessage *py_part = PyMessage_NEW ();
 
-  if (!PyArg_ParseTuple (args, "O!i", &PyMessageType, &py_msg, &npart))
+  if (!PyArg_ParseTuple (args, "O!n", &PyMessageType, &py_msg, &npart))
     return NULL;
-
+  ASSERT_INDEX_RANGE (npart, "message part");
   status = mu_message_get_part (py_msg->msg, npart, &py_part->msg);
 
   Py_INCREF (py_part);
@@ -254,7 +254,7 @@ api_message_get_uid (PyObject *self, PyObject *args)
     return NULL;
 
   status = mu_message_get_uid (py_msg->msg, &uid);
-  return status_object (status, PyInt_FromLong (uid));
+  return status_object (status, PyInt_FromSize_t (uid));
 }
 
 static PyObject *
diff --git a/python/libmu_py/mime.c b/python/libmu_py/mime.c
index 5cf6e9d..95f2ff9 100644
--- a/python/libmu_py/mime.c
+++ b/python/libmu_py/mime.c
@@ -133,20 +133,20 @@ api_mime_get_num_parts (PyObject *self, PyObject *args)
     return NULL;
 
   status = mu_mime_get_num_parts (py_mime->mime, &nparts);
-  return status_object (status, PyInt_FromLong (nparts));
+  return status_object (status, PyInt_FromSize_t (nparts));
 }
 
 static PyObject *
 api_mime_get_part (PyObject *self, PyObject *args)
 {
   int status;
-  size_t npart;
+  Py_ssize_t npart;
   PyMime *py_mime;
   PyMessage *py_part = PyMessage_NEW ();
 
-  if (!PyArg_ParseTuple (args, "O!i", &PyMimeType, &py_mime, &npart))
+  if (!PyArg_ParseTuple (args, "O!n", &PyMimeType, &py_mime, &npart))
     return NULL;
-
+  ASSERT_INDEX_RANGE (npart, "mime part");
   status = mu_mime_get_part (py_mime->mime, npart, &py_part->msg);
 
   Py_INCREF (py_part);
diff --git a/python/libmu_py/secret.c b/python/libmu_py/secret.c
index 1c07881..1570ff2 100644
--- a/python/libmu_py/secret.c
+++ b/python/libmu_py/secret.c
@@ -87,13 +87,17 @@ api_secret_create (PyObject *self, PyObject *args)
 {
   int status;
   char *str;
-  size_t len;
+  Py_ssize_t len;
   PySecret *py_secret;
 
-  if (!PyArg_ParseTuple (args, "O!si", &PySecretType, &py_secret,
+  if (!PyArg_ParseTuple (args, "O!sn", &PySecretType, &py_secret,
                         &str, &len))
     return NULL;
-
+  if (len <= 0)
+    {
+      PyErr_SetString (PyExc_RuntimeError, "secret length out of range");
+      return NULL;
+    }
   status = mu_secret_create (&py_secret->secret, str, len);
   return _ro (PyInt_FromLong (status));
 }
diff --git a/python/libmu_py/sieve.c b/python/libmu_py/sieve.c
index 421b4eb..58c096e 100644
--- a/python/libmu_py/sieve.c
+++ b/python/libmu_py/sieve.c
@@ -263,7 +263,7 @@ _sieve_action_printer (void *data, mu_stream_t stream,
              Py_INCREF (py_msg);
 
              PyDict_SetItemString (py_dict, "msgno",
-                                   PyInt_FromLong (msgno));
+                                   PyInt_FromSize_t (msgno));
              PyDict_SetItemString (py_dict, "msg", (PyObject *)py_msg);
              PyDict_SetItemString (py_dict, "action",
                                    PyString_FromString (action ? action : ""));
diff --git a/python/libmu_py/stream.c b/python/libmu_py/stream.c
index 5edac86..d4e70c6 100644
--- a/python/libmu_py/stream.c
+++ b/python/libmu_py/stream.c
@@ -294,7 +294,7 @@ api_stream_read (PyObject *self, PyObject *args)
   py_ret = PyTuple_New (3);
   PyTuple_SetItem (py_ret, 0, PyInt_FromLong (status));
   PyTuple_SetItem (py_ret, 1, PyString_FromString (rbuf));
-  PyTuple_SetItem (py_ret, 2, PyInt_FromLong (read_count));
+  PyTuple_SetItem (py_ret, 2, PyInt_FromSize_t (read_count));
   return _ro (py_ret);
 }
 
@@ -303,14 +303,19 @@ api_stream_write (PyObject *self, PyObject *args)
 {
   int status;
   char *wbuf;
-  size_t size, write_count;
+  Py_ssize_t size;
+  size_t write_count;
   PyStream *py_stm;
 
-  if (!PyArg_ParseTuple (args, "O!si", &PyStreamType, &py_stm, &wbuf, &size))
+  if (!PyArg_ParseTuple (args, "O!sn", &PyStreamType, &py_stm, &wbuf, &size))
     return NULL;
-
+  if (size < 0)
+    {
+      PyErr_SetString (PyExc_RuntimeError, "negative size");
+      return NULL;
+    }
   status = mu_stream_write (py_stm->stm, wbuf, size, &write_count);
-  return status_object (status, PyInt_FromLong (write_count));
+  return status_object (status, PyInt_FromSize_t (write_count));
 }
 
 static PyObject *
@@ -332,7 +337,7 @@ api_stream_readline (PyObject *self, PyObject *args)
   py_ret = PyTuple_New (3);
   PyTuple_SetItem (py_ret, 0, PyInt_FromLong (status));
   PyTuple_SetItem (py_ret, 1, PyString_FromString (rbuf));
-  PyTuple_SetItem (py_ret, 2, PyInt_FromLong (read_count));
+  PyTuple_SetItem (py_ret, 2, PyInt_FromSize_t (read_count));
   return _ro (py_ret);
 }
 


hooks/post-receive
-- 
GNU Mailutils



reply via email to

[Prev in Thread] Current Thread [Next in Thread]