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-733-gad3cc34


From: Sergey Poznyakoff
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-733-gad3cc34
Date: Sat, 19 Sep 2015 10:38:35 +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=ad3cc340266af4e1d768e6d3e59594f78cd6f940

The branch, master has been updated
       via  ad3cc340266af4e1d768e6d3e59594f78cd6f940 (commit)
      from  f160ca75991d5bf994afe3cb5bc549b113b14bbd (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 ad3cc340266af4e1d768e6d3e59594f78cd6f940
Author: Sergey Poznyakoff <address@hidden>
Date:   Sat Sep 19 13:23:50 2015 +0300

    Complement f160ca75
    
    * include/mailutils/wordsplit.h (MU_WRDSX_WORD)
    (MU_WRDSX_QUOTE): New constants.
    (mu_wordsplit_getwords): Rename to mu_wordsplit_get_words.
    * libmailutils/string/wordsplit.c (mu_wordsplit_getwords): Rename
    to mu_wordsplit_get_words.
    
    * libmailutils/base/userprivs.c (mu_switch_to_privs): Fix
    memory overrun when retrieving the current pointer.
    
    * examples/header.c (main): Use mu_wordsplit_get_words
    * imap4d/preauth.c (preauth_getvar): Rewrite according to
    the new API.
    * libmailutils/imapio/create.c (mu_imapio_create): Use MU_WRDSX_
    constants to address ws_escape.
    * libmailutils/imapio/qstring.c: Likewise.
    * libmailutils/mailbox/mbx_default.c: Minor fix.
    * libmailutils/server/acl.c (acl_getvar): Rewrite according to
    the new API.
    * libmailutils/tests/wsp.c: Minor fix.
    * libmailutils/url/create.c (_mu_url_create_internal): Bugfix: alloc
    url->path.
    * libmu_sieve/extensions/list.c (retrieve_next_header): Use
    mu_wordsplit_get_words
    * libproto/mailer/prog.c (prog_getvar): Rewrite according to
    the new API.
    * libproto/mailer/smtp_gsasl.c (get_implemented_mechs): Remove
    unneeded assignment to ws.ws_wordv.
    * mh/folder.c: Use mu_wordsplit_get_words.
    * mh/mhn.c: Likewise.
    * movemail/movemail.c (movemail_getvar): Rewrite according to
    the new API.

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

Summary of changes:
 examples/header.c                  |    7 +--
 imap4d/preauth.c                   |   41 +++++++----
 include/mailutils/wordsplit.h      |   13 +++-
 libmailutils/base/userprivs.c      |   11 ++-
 libmailutils/imapio/create.c       |    4 +-
 libmailutils/imapio/qstring.c      |    5 +-
 libmailutils/mailbox/mbx_default.c |    1 +
 libmailutils/server/acl.c          |   66 ++++++++---------
 libmailutils/string/wordsplit.c    |   11 ++-
 libmailutils/tests/wsp.c           |    7 +-
 libmailutils/url/create.c          |    7 ++-
 libmu_sieve/extensions/list.c      |    7 +--
 libproto/mailer/prog.c             |  141 +++++++++++++++++++-----------------
 libproto/mailer/smtp_gsasl.c       |    1 -
 mh/folder.c                        |   19 ++---
 mh/mhn.c                           |   21 +++---
 movemail/movemail.c                |   69 +++++++++++-------
 17 files changed, 236 insertions(+), 195 deletions(-)

diff --git a/examples/header.c b/examples/header.c
index 9d0f6df..2ed4a55 100644
--- a/examples/header.c
+++ b/examples/header.c
@@ -558,7 +558,7 @@ main (int argc, char **argv)
   int c;
   char buf[512];
   char **prevv = NULL;
-  int prevc = 0;
+  size_t prevc = 0;
 
   interactive = isatty (0);
   while ((c = getopt (argc, argv, "f:h")) != EOF)
@@ -615,10 +615,7 @@ main (int argc, char **argv)
        {
          docmd (ws.ws_wordc, ws.ws_wordv);
          mu_argcv_free (prevc, prevv);
-         prevc = ws.ws_wordc;
-         prevv = ws.ws_wordv;
-         ws.ws_wordc = 0;
-         ws.ws_wordv = NULL;
+         mu_wordsplit_get_words (&ws, &prevc, &prevv);
        }
       mu_wordsplit_free (&ws);
     }
diff --git a/imap4d/preauth.c b/imap4d/preauth.c
index d50e2d8..104e415 100644
--- a/imap4d/preauth.c
+++ b/imap4d/preauth.c
@@ -395,26 +395,41 @@ struct preauth_closure
   struct sockaddr_in *s_clt, *s_srv;
 };
 
-static const char *
-preauth_getvar (const char *name, size_t nlen, void *data)
+static int
+preauth_getvar (char **ret, const char *name, size_t nlen, void *data)
 {
   struct preauth_closure *clos = data;
+  const char *s = NULL;
   
-  if (clos->s_clt && clos->s_clt->sin_family == AF_INET)
+  if (SEQ ("client_address", name, nlen))
     {
-      if (SEQ ("client_address", name, nlen))
-        return inet_ntoa (clos->s_clt->sin_addr);
-      if (SEQ ("client_prot", name, nlen))
-        return mu_umaxtostr (0, ntohs (clos->s_clt->sin_port));
+      if (clos->s_clt && clos->s_clt->sin_family == AF_INET)
+        s = inet_ntoa (clos->s_clt->sin_addr);
     }
-  if (clos->s_srv && clos->s_srv->sin_family == AF_INET)
+  else if (SEQ ("client_port", name, nlen))
     {
-      if (SEQ ("server_address", name, nlen))
-        return inet_ntoa (clos->s_srv->sin_addr);
-      if (SEQ ("server_port", name, nlen))
-        return mu_umaxtostr (0, ntohs (clos->s_srv->sin_port));
+      if (clos->s_clt && clos->s_clt->sin_family == AF_INET)
+        s = mu_umaxtostr (0, ntohs (clos->s_clt->sin_port));
     }
-  return NULL;
+  else if (SEQ ("server_address", name, nlen))
+    {
+      if (clos->s_srv && clos->s_srv->sin_family == AF_INET)
+        s = inet_ntoa (clos->s_srv->sin_addr);
+    }
+  else if (SEQ ("server_port", name, nlen))
+    {
+      if (clos->s_srv && clos->s_srv->sin_family == AF_INET)
+        s = mu_umaxtostr (0, ntohs (clos->s_srv->sin_port));
+    }
+  
+  if (s)
+    {
+      *ret = strdup (s);
+      if (!*ret)
+       return MU_WRDSE_NOSPACE;
+      return MU_WRDSE_OK;
+    }
+  return MU_WRDSE_UNDEF;
 }
   
 /* External (program) preauth */
diff --git a/include/mailutils/wordsplit.h b/include/mailutils/wordsplit.h
index aaf4bd7..0d525d1 100644
--- a/include/mailutils/wordsplit.h
+++ b/include/mailutils/wordsplit.h
@@ -70,9 +70,9 @@ struct mu_wordsplit
   int (*ws_getvar) (char **ret, const char *var, size_t len, void *clos);
                             /* [Input] (MU_WRDSF_GETVAR, !MU_WRDSF_NOVAR) 
Looks up
                               the name VAR (LEN bytes long) in the table of
-                              variables and if found returns in memory
-                              location pointed to by RET the value of that
-                              variable.  Returns WRDSE_OK (0) on success,
+                              variables and, if found returns the value of
+                              that variable in memory location pointed to
+                              by RET .  Returns WRDSE_OK (0) on success,
                               and an error code (see WRDSE_* defines below)
                               on error.  User-specific errors can be returned
                               by storing the error diagnostic string in RET
@@ -213,6 +213,10 @@ struct mu_wordsplit
 #define MU_WRDSO_OESC            MU_WRDSO_OESC_WORD       
 #define MU_WRDSO_XESC            MU_WRDSO_XESC_WORD       
 
+/* Indices into ws_escape */
+#define MU_WRDSX_WORD  0
+#define MU_WRDSX_QUOTE 1    
+  
 /* Set escape option F in WS for words (Q==0) or quoted strings (Q==1) */
 #define MU_WRDSO_ESC_SET(ws,q,f) ((ws)->ws_options |= ((f) << 4*(q)))
 /* Test WS for escape option F for words (Q==0) or quoted strings (Q==1) */
@@ -235,7 +239,8 @@ int mu_wordsplit_len (const char *s, size_t len, 
mu_wordsplit_t *ws, int flags);
 void mu_wordsplit_free (mu_wordsplit_t *ws);
 void mu_wordsplit_free_words (mu_wordsplit_t *ws);
 void mu_wordsplit_free_envbuf (mu_wordsplit_t *ws);
-void mu_wordsplit_getwords (mu_wordsplit_t *ws, int *wordc, char ***wordv);
+
+int mu_wordsplit_get_words (mu_wordsplit_t *ws, size_t *wordc, char ***wordv);
 
 int mu_wordsplit_c_unquote_char (int c);
 int mu_wordsplit_c_quote_char (int c);
diff --git a/libmailutils/base/userprivs.c b/libmailutils/base/userprivs.c
index 2f91376..e559d35 100644
--- a/libmailutils/base/userprivs.c
+++ b/libmailutils/base/userprivs.c
@@ -180,7 +180,7 @@ mu_switch_to_privs (uid_t uid, gid_t gid, mu_list_t 
retain_groups)
   /* Create a list of supplementary groups */
   mu_list_count (retain_groups, &size);
   size++;
-  emptygidset = malloc (size * sizeof emptygidset[0]);
+  emptygidset = calloc (size, sizeof emptygidset[0]);
   if (!emptygidset)
     return ENOMEM;
   emptygidset[0] = gid ? gid : getegid ();
@@ -188,9 +188,12 @@ mu_switch_to_privs (uid_t uid, gid_t gid, mu_list_t 
retain_groups)
   if (mu_list_get_iterator (retain_groups, &itr) == 0)
     {
       for (mu_iterator_first (itr);
-          !mu_iterator_is_done (itr); mu_iterator_next (itr)) 
-       mu_iterator_current (itr,
-                            (void **)(emptygidset + j++));
+          !mu_iterator_is_done (itr); mu_iterator_next (itr))
+       {
+         void *p;
+         mu_iterator_current (itr, &p);
+         emptygidset[j++] = (gid_t) (intptr_t) p;
+       }
       mu_iterator_destroy (&itr);
     }
   rc = mu_set_user_privileges (uid, emptygidset, j);
diff --git a/libmailutils/imapio/create.c b/libmailutils/imapio/create.c
index 9d83c4d..41e9bb1 100644
--- a/libmailutils/imapio/create.c
+++ b/libmailutils/imapio/create.c
@@ -29,8 +29,8 @@ mu_imapio_create (mu_imapio_t *iop, mu_stream_t str, int 
server)
   io->_imap_stream = str;
   mu_stream_ref (str);
   io->_imap_ws.ws_delim = " \t()[]";
-  io->_imap_ws.ws_escape[0] = NULL;
-  io->_imap_ws.ws_escape[1] = "\\\\\"\"";
+  io->_imap_ws.ws_escape[MU_WRDSX_WORD] = NULL;
+  io->_imap_ws.ws_escape[MU_WRDSX_QUOTE] = "\\\\\"\"";
   MU_WRDSO_ESC_SET (&io->_imap_ws, 0, MU_WRDSO_BSKEEP);
   MU_WRDSO_ESC_SET (&io->_imap_ws, 1, MU_WRDSO_BSKEEP);
   io->_imap_ws_flags = MU_WRDSF_DELIM |
diff --git a/libmailutils/imapio/qstring.c b/libmailutils/imapio/qstring.c
index c9cf424..dc6bc8f 100644
--- a/libmailutils/imapio/qstring.c
+++ b/libmailutils/imapio/qstring.c
@@ -66,7 +66,8 @@ mu_imapio_send_qstring_unfold (struct _mu_imapio *io, const 
char *buffer,
       else
        mu_imapio_send_literal_string (io, buffer);
     }
-  else if (buffer[len = strcspn (buffer, io->_imap_ws.ws_escape)])
+  else if (io->_imap_ws.ws_escape[MU_WRDSX_QUOTE]
+          && buffer[len = strcspn (buffer, 
io->_imap_ws.ws_escape[MU_WRDSX_QUOTE])])
     {
       int rc;
       
@@ -82,7 +83,7 @@ mu_imapio_send_qstring_unfold (struct _mu_imapio *io, const 
char *buffer,
              mu_stream_write (io->_imap_stream, "\\", 1, NULL);
              mu_stream_write (io->_imap_stream, buffer, 1, NULL);
              buffer++;
-             len = strcspn (buffer, io->_imap_ws.ws_escape);
+             len = strcspn (buffer, io->_imap_ws.ws_escape[MU_WRDSX_QUOTE]);
            }
          else
            break;
diff --git a/libmailutils/mailbox/mbx_default.c 
b/libmailutils/mailbox/mbx_default.c
index 5082027..6ad4e04 100644
--- a/libmailutils/mailbox/mbx_default.c
+++ b/libmailutils/mailbox/mbx_default.c
@@ -39,6 +39,7 @@
 #include <mailutils/folder.h>
 #include <mailutils/auth.h>
 #include <mailutils/wordsplit.h>
+#include <mailutils/io.h>
 
 #include <mailutils/sys/mailbox.h>
 
diff --git a/libmailutils/server/acl.c b/libmailutils/server/acl.c
index 069fdec..6c19102 100644
--- a/libmailutils/server/acl.c
+++ b/libmailutils/server/acl.c
@@ -71,7 +71,6 @@ struct run_closure
   char **env;
   char ipstr[40];
   char *addrstr;
-  char *numbuf;
   mu_acl_result_t *result;
 };
 
@@ -305,57 +304,54 @@ _acl_match (struct _mu_acl_entry *ent, struct run_closure 
*rp)
 #define SEQ(s, n, l) \
   (((l) == (sizeof(s) - 1)) && memcmp (s, n, l) == 0)
 
-static const char *
-acl_getvar (const char *name, size_t nlen, void *data)
+static int
+acl_getvar (char **ret, const char *name, size_t nlen, void *data)
 {
   struct run_closure *rp = data;
 
-  if (SEQ ("family", name, nlen))
+  if (SEQ ("aclno", name, nlen))
+    {
+      if (mu_asprintf (ret, "%u", rp->idx))
+       return MU_WRDSE_NOSPACE;
+      return MU_WRDSE_OK;
+    }
+  else if (SEQ ("address", name, nlen))
+    {
+      if (mu_cidr_format (&rp->addr, MU_CIDR_FMT_ADDRONLY, ret))
+       return MU_WRDSE_NOSPACE;
+      return MU_WRDSE_OK;
+    }
+  else if (SEQ ("family", name, nlen))
     {
+      char *s;
+      
       switch (rp->addr.family)
        {
        case AF_INET:
-         return "AF_INET";
+         s = "AF_INET";
+         break;
 
 #ifdef MAILUTILS_IPV6
        case AF_INET6:
-         return "AF_INET6";
+         s = "AF_INET6";
+         break;
 #endif
       
        case AF_UNIX:
-         return "AF_UNIX";
+         s = "AF_UNIX";
+         break;
 
        default:
-         return NULL;
+         return MU_WRDSE_UNDEF;
        }
-    }
-  
-  if (SEQ ("aclno", name, nlen))
-    {
-      if (!rp->numbuf && mu_asprintf (&rp->numbuf, "%u", rp->idx))
-       return NULL;
-      return rp->numbuf;
-    }
-  
-  if (SEQ ("address", name, nlen))
-    {
-      if (!rp->addrstr)
-       mu_cidr_format (&rp->addr, MU_CIDR_FMT_ADDRONLY, &rp->addrstr);
-      return rp->addrstr;
-    }
 
-#if 0
-  /* FIXME?: */
-  if (SEQ ("port", name, nlen))
-    {
-      if (!rp->portbuf &&
-         mu_asprintf (&rp->portbuf, "%hu", ntohs (s_in->sin_port)))
-       return NULL;
-      return rp->portbuf;
+      *ret = strdup (s);
+      if (!*ret)
+       return MU_WRDSE_NOSPACE;
+      return MU_WRDSE_OK;
     }
-#endif
-
-  return NULL;
+  
+  return MU_WRDSE_UNDEF;
 }
 
 static int
@@ -577,9 +573,7 @@ mu_acl_check_sockaddr (mu_acl_t acl, const struct sockaddr 
*sa, int salen,
   r.result = pres;
   r.env = acl->envv;
   *r.result = mu_acl_result_undefined;
-  r.numbuf = NULL;
   mu_list_foreach (acl->aclist, _run_entry, &r);
-  free (r.numbuf);
   free (r.addrstr);
   return 0;
 }
diff --git a/libmailutils/string/wordsplit.c b/libmailutils/string/wordsplit.c
index 755f5d4..b570ccf 100644
--- a/libmailutils/string/wordsplit.c
+++ b/libmailutils/string/wordsplit.c
@@ -2282,16 +2282,21 @@ mu_wordsplit_free (struct mu_wordsplit *ws)
   mu_wordsplit_free_envbuf (ws);
 }
 
-void
-mu_wordsplit_getwords (struct mu_wordsplit *ws, int *wordc, char ***wordv)
+int
+mu_wordsplit_get_words (struct mu_wordsplit *ws, size_t *wordc, char ***wordv)
 {
   char **p = realloc (ws->ws_wordv,
                      (ws->ws_wordc + 1) * sizeof (ws->ws_wordv[0]));
-  *wordv = p ? p : ws->ws_wordv;
+  if (!p)
+    return -1;
+  *wordv = p;
   *wordc = ws->ws_wordc;
+
   ws->ws_wordv = NULL;
   ws->ws_wordc = 0;
   ws->ws_wordn = 0;
+
+  return 0;
 }
 
 const char *_mu_wordsplit_errstr[] = {
diff --git a/libmailutils/tests/wsp.c b/libmailutils/tests/wsp.c
index 28b7b36..7c30971 100644
--- a/libmailutils/tests/wsp.c
+++ b/libmailutils/tests/wsp.c
@@ -27,6 +27,7 @@
 #include <mailutils/errno.h>
 #include <mailutils/error.h>
 #include <mailutils/cstr.h>
+#include <mailutils/io.h>
 
 extern char **environ;
 
@@ -199,13 +200,11 @@ wsp_runcmd (char **ret, const char *str, size_t len, char 
**argv, void *closure)
   memcpy (cmd, str, len);
   cmd[len] = 0;
 
-  fp = popen(cmd, "r");
+  fp = popen (cmd, "r");
   if (!fp)
     {
-      size_t size = 0;
       ret = NULL;
-      if (mu_asprintf (ret, &size, "can't run %s: %s",
-                      cmd, strerror (errno)))
+      if (mu_asprintf (ret, "can't run %s: %s", cmd, mu_strerror (errno)))
        return MU_WRDSE_NOSPACE;
       else
        return MU_WRDSE_USERERR;
diff --git a/libmailutils/url/create.c b/libmailutils/url/create.c
index 182b8bd..95deca4 100644
--- a/libmailutils/url/create.c
+++ b/libmailutils/url/create.c
@@ -416,7 +416,12 @@ _mu_url_create_internal (struct mu_url_ctx *ctx, mu_url_t 
hint)
       ctx->flags &= ~MU_URL_PARSE_HEXCODE;
       if (mu_wordsplit (ctx->input + 1, &ws, MU_WRDSF_DEFFLAGS))
        return errno;
-      url->path = ws.ws_wordv[0];
+      url->path = strdup (ws.ws_wordv[0]);
+      if (!url->path)
+       {
+         mu_wordsplit_free (&ws);
+         return ENOMEM;
+       }
       url->flags |= MU_URL_PATH;
       
       url->qargc = ws.ws_wordc - 1;
diff --git a/libmu_sieve/extensions/list.c b/libmu_sieve/extensions/list.c
index 702aca5..2909d96 100644
--- a/libmu_sieve/extensions/list.c
+++ b/libmu_sieve/extensions/list.c
@@ -81,12 +81,9 @@ retrieve_next_header (struct header_closure *hc, char *name, 
char **pval)
              mu_wordsplit_free (&ws);
              return 1;
            }
-         hc->valv = ws.ws_wordv;
-         hc->valc = ws.ws_wordc;
-         hc->vali = 0;
-         ws.ws_wordv = NULL;
-         ws.ws_wordc = 0;
+         mu_wordsplit_get_words (&ws, &hc->valc, &hc->valv);
          mu_wordsplit_free (&ws);
+         hc->vali = 0;
          *pval = hc->valv[hc->vali++];
          return 0;
        }
diff --git a/libproto/mailer/prog.c b/libproto/mailer/prog.c
index 2fcda6f..4ad0601 100644
--- a/libproto/mailer/prog.c
+++ b/libproto/mailer/prog.c
@@ -33,6 +33,7 @@
 #include <mailutils/observer.h>
 #include <mailutils/progmailer.h>
 #include <mailutils/wordsplit.h>
+#include <mailutils/io.h>
 
 #include <mailutils/sys/url.h>
 #include <mailutils/sys/mailer.h>
@@ -143,18 +144,30 @@ struct prog_exp
 {
   mu_message_t msg;
   mu_address_t sender_addr;
-  char *sender_str;
   mu_address_t rcpt_addr;
-  char *rcpt_str;
 };
 
-static const char *
-_expand_sender (struct prog_exp *pe)
+static int
+_expand_err (char **ret, const char *prefix, int status)
+{
+  if (mu_asprintf (ret, "%s: %s", prefix, mu_strerror (status)))
+    return MU_WRDSE_NOSPACE;
+  return MU_WRDSE_USERERR;
+}
+
+static int
+_expand_sender (struct prog_exp *pe, char **ret)
 {
-  if (!pe->sender_str &&
-      mu_address_aget_email (pe->sender_addr, 1, &pe->sender_str))
-    return NULL;
-  return pe->sender_str;
+  int status = mu_address_aget_email (pe->sender_addr, 1, ret);
+  switch (status)
+    {
+    case 0:
+      return MU_WRDSE_OK;
+
+    case ENOMEM:
+      return MU_WRDSE_NOSPACE;
+    }
+  return _expand_err (ret, "getting email", status);
 }
 
 static int
@@ -203,82 +216,79 @@ message_read_rcpt (mu_message_t msg, mu_address_t *paddr)
   return 0;
 }
 
-static const char *
-_expand_rcpt (struct prog_exp *pe)
+static int
+_expand_rcpt (struct prog_exp *pe, char **ret)
 {
   int status;
-
-  if (!pe->rcpt_str)
-    {
-      size_t i, count = 0;
-      size_t len = 0;
-      char *str;
-      mu_address_t tmp_addr = NULL, addr;
+  size_t i, count = 0;
+  size_t len = 0;
+  char *str;
+  mu_address_t tmp_addr = NULL, addr;
       
-      if (pe->rcpt_addr)
-       addr = pe->rcpt_addr;
-      else
+  if (pe->rcpt_addr)
+    addr = pe->rcpt_addr;
+  else
+    {
+      status = message_read_rcpt (pe->msg, &tmp_addr);
+      if (status)
        {
-         status = message_read_rcpt (pe->msg, &tmp_addr);
-         if (status)
-           {
-             mu_address_destroy (&tmp_addr);
-             return NULL;
-           }
-         addr = tmp_addr;
+         mu_address_destroy (&tmp_addr);
+         return _expand_err (ret, "reading recipients", status);
        }
+      addr = tmp_addr;
+    }
            
-      mu_address_get_count (addr, &count);
-      for (i = 1; i <= count; i++)
-       {
-         const char *email;
-         if (i > 1)
-           len++;
-         if ((status = mu_address_sget_email (addr, i, &email)) != 0)
-           {
-             mu_address_destroy (&tmp_addr);
-             return NULL;
-           }
-         len += strlen (email);
-       }
-
-      str = malloc (len + 1);
-      if (!str)
+  mu_address_get_count (addr, &count);
+  for (i = 1; i <= count; i++)
+    {
+      const char *email;
+      if (i > 1)
+       len++;
+      if ((status = mu_address_sget_email (addr, i, &email)) != 0)
        {
          mu_address_destroy (&tmp_addr);
-         return NULL;
-       }
-      pe->rcpt_str = str;
-      
-      for (i = 1; i <= count; i++)
-       {
-         const char *email;
-         if (i > 1)
-           *str++ = ' ';
-         if (mu_address_sget_email (addr, i, &email))
-           continue;
-         strcpy (str, email);
-         str += strlen (email);
+         return _expand_err (ret, "reading email", status);
        }
-      *str = 0;
+      len += strlen (email);
+    }
+
+  str = malloc (len + 1);
+  if (!str)
+    {
       mu_address_destroy (&tmp_addr);
-    }  
-  return pe->rcpt_str;
+      return MU_WRDSE_NOSPACE;
+    }
+  *ret = str;
+      
+  for (i = 1; i <= count; i++)
+    {
+      const char *email;
+      if (i > 1)
+       *str++ = ' ';
+      if (mu_address_sget_email (addr, i, &email))
+       continue;
+      strcpy (str, email);
+      str += strlen (email);
+    }
+  *str = 0;
+  mu_address_destroy (&tmp_addr);
+  
+  return MU_WRDSE_OK;
 }
 
 #define SEQ(s, n, l) \
   (((l) == (sizeof(s) - 1)) && memcmp (s, n, l) == 0)
 
-static const char *
-prog_getvar (const char *name, size_t nlen, void *data)
+static int
+prog_getvar (char **ret, const char *name, size_t nlen, void *data)
 {
   struct prog_exp *pe = data;
   
   if (SEQ ("sender", name, nlen))
-    return _expand_sender (pe);
+    return _expand_sender (pe, ret);
   if (SEQ ("rcpt", name, nlen))
-    return _expand_rcpt (pe);
-  return NULL;
+    return _expand_rcpt (pe, ret);
+  return MU_WRDSE_UNDEF;
 }
 
 static int
@@ -298,7 +308,6 @@ url_to_argv (mu_url_t url, mu_message_t msg,
   pe.msg = msg;
   pe.rcpt_addr = to;
   pe.sender_addr = from;
-  pe.sender_str = pe.rcpt_str = NULL;
 
   ws.ws_getvar = prog_getvar;
   ws.ws_closure = &pe;
@@ -341,8 +350,6 @@ url_to_argv (mu_url_t url, mu_message_t msg,
     }
   argv[i+1] = NULL;
   mu_wordsplit_free (&ws);
-  free (pe.sender_str);
-  free (pe.rcpt_str);
   
   *pargc = argc;
   *pargv = argv;
diff --git a/libproto/mailer/smtp_gsasl.c b/libproto/mailer/smtp_gsasl.c
index 9870457..1ae992f 100644
--- a/libproto/mailer/smtp_gsasl.c
+++ b/libproto/mailer/smtp_gsasl.c
@@ -69,7 +69,6 @@ get_implemented_mechs (Gsasl *ctx, mu_list_t *plist)
            mu_list_append (supp, ws.ws_wordv[i]);
        }
       ws.ws_wordc = 0;
-      ws.ws_wordv = NULL;
       mu_wordsplit_free (&ws);
     }
   free (listmech);
diff --git a/mh/folder.c b/mh/folder.c
index dd5b5ac..0807dd7 100644
--- a/mh/folder.c
+++ b/mh/folder.c
@@ -518,7 +518,7 @@ action_list ()
 /* Push & pop */
 
 static void
-get_stack (int *pc, char ***pv)
+get_stack (size_t *pc, char ***pv)
 {
   struct mu_wordsplit ws;
   const char *stack = mh_global_context_get ("Folder-Stack", NULL);
@@ -535,10 +535,7 @@ get_stack (int *pc, char ***pv)
     }
   else
     {
-      *pc = ws.ws_wordc;
-      *pv = ws.ws_wordv;
-      ws.ws_wordc = 0;
-      ws.ws_wordv = NULL;
+      mu_wordsplit_get_words (&ws, pc, pv);
       mu_wordsplit_free (&ws);
     }
 }
@@ -559,9 +556,9 @@ set_stack (int c, char **v)
 }
 
 static void
-push_val (int *pc, char ***pv, const char *val)
+push_val (size_t *pc, char ***pv, const char *val)
 {
-  int c = *pc;
+  size_t c = *pc;
   char **v = *pv;
 
   c++;
@@ -581,10 +578,10 @@ push_val (int *pc, char ***pv, const char *val)
 }
 
 static char *
-pop_val (int *pc, char ***pv)
+pop_val (size_t *pc, char ***pv)
 {
   char *val;
-  int c;
+  size_t c;
   char **v;
   
   if (*pc == 0)
@@ -603,7 +600,7 @@ pop_val (int *pc, char ***pv)
 static int
 action_push ()
 {
-  int c;
+  size_t c;
   char **v;
 
   get_stack (&c, &v);
@@ -628,7 +625,7 @@ action_push ()
 static int
 action_pop ()
 {
-  int c;
+  size_t c;
   char **v;
 
   get_stack (&c, &v);
diff --git a/mh/mhn.c b/mh/mhn.c
index e092d83..6bde07d 100644
--- a/mh/mhn.c
+++ b/mh/mhn.c
@@ -199,7 +199,7 @@ split_content (const char *content, char **type, char 
**subtype)
 }
 
 static void
-split_args (const char *argstr, size_t len, int *pargc, char ***pargv)
+split_args (const char *argstr, size_t len, size_t *pargc, char ***pargv)
 {
   struct mu_wordsplit ws;
 
@@ -215,10 +215,7 @@ split_args (const char *argstr, size_t len, int *pargc, 
char ***pargv)
     }
   else
     {
-      *pargc = ws.ws_wordc;
-      *pargv = ws.ws_wordv;
-      ws.ws_wordc = 0;
-      ws.ws_wordv = NULL;
+      mu_wordsplit_get_words (&ws, pargc, pargv);
       mu_wordsplit_free (&ws);
     }
 }
@@ -631,7 +628,7 @@ mhn_compose_command (char *typestr, char *typeargs, int 
*flags, char *file)
 {
   const char *p, *str;
   char *type, *subtype, **typeargv = NULL;
-  int typeargc = 0;
+  size_t typeargc = 0;
   mu_opool_t pool;
 
   split_content (typestr, &type, &subtype);
@@ -662,7 +659,7 @@ mhn_compose_command (char *typestr, char *typeargs, int 
*flags, char *file)
              /* additional arguments */
              if (typeargs)
                {
-                 int i;
+                 size_t i;
                  
                  if (!typeargv)
                    split_args (typeargs, strlen (typeargs),
@@ -741,7 +738,7 @@ check_type (const char *typeargs, const char *typeval)
   
   if (typeargs)
     {
-      int i, argc;
+      size_t i, argc;
       char **argv;
                      
       split_args (typeargs, strlen (typeargs), &argc, &argv);
@@ -769,7 +766,7 @@ mhn_show_command (mu_message_t msg, msg_part_t part, int 
*flags,
   mu_opool_t pool;
   mu_header_t hdr;
   char *temp_cmd = NULL;
-  int typeargc = 0;
+  size_t typeargc = 0;
   char **typeargv = NULL;
   
   mu_message_get_header (msg, &hdr);
@@ -1084,7 +1081,7 @@ _message_is_external_body (mu_message_t msg, char ***env)
   rc = subtype && strcmp (subtype, "external-body") == 0;
   if (rc && env)
     {
-      int c;
+      size_t c;
       split_args (argstr, strlen (argstr), &c, env);
     }
 
@@ -2753,7 +2750,7 @@ parse_header_directive (const char *val, char **encoding, 
char **charset,
       p = strchr (val, '>');
       if (p)
        {
-         int i, argc;
+         size_t i, argc;
          char **argv;
            
          *subject = mu_strdup (p + 1);
@@ -2819,7 +2816,7 @@ mhn_header (mu_message_t msg, mu_message_t omsg)
                  _get_content_encoding (parthdr, &encoding);
                  if (typeargs)
                    {
-                     int i, argc;
+                     size_t i, argc;
                      char **argv;
                      
                      split_args (typeargs, strlen (typeargs), &argc, &argv);
diff --git a/movemail/movemail.c b/movemail/movemail.c
index 29c2302..0216dab 100644
--- a/movemail/movemail.c
+++ b/movemail/movemail.c
@@ -757,46 +757,66 @@ struct movemail_getvar_closure
 #define SEQ(s, n, l) \
   (((l) == (sizeof(s) - 1)) && memcmp (s, n, l) == 0)
 
-static const char *
-get_url_part (mu_url_t url, const char *name, size_t nlen)
+static int
+get_url_part (mu_url_t url, const char *name, size_t nlen, char **ret)
 {
-  int rc = MU_ERR_NOENT;
-  const char *s;
+  int rc;
   
   if (!url)
-    return NULL;
+    return MU_WRDSE_UNDEF;
   if (SEQ ("user", name, nlen))
-    rc = mu_url_sget_user (url, &s);
+    rc = mu_url_aget_user (url, ret);
   else if (SEQ ("host", name, nlen))
-    rc = mu_url_sget_host (url, &s);
+    rc = mu_url_aget_host (url, ret);
   else if (SEQ ("port", name, nlen))
-    rc = mu_url_sget_portstr (url, &s);
+    rc = mu_url_aget_portstr (url, ret);
   else if (SEQ ("path", name, nlen))
-    rc = mu_url_sget_path (url, &s);
+    rc = mu_url_aget_path (url, ret);
+  else
+    return MU_WRDSE_UNDEF;
 
-  if (rc)
-    return NULL;
-  return s;
+  switch (rc)
+    {
+    case 0:
+      break;
+      
+    case MU_ERR_NOENT:
+      return MU_WRDSE_UNDEF;
+
+    default:
+      if (mu_asprintf (ret, "%s", mu_strerror (rc)))
+       return MU_WRDSE_NOSPACE;
+      return MU_WRDSE_USERERR;
+    }
+  
+  return MU_WRDSE_OK;
 }
     
-static const char *
-movemail_getvar (const char *name, size_t nlen, void *data)
+static int
+movemail_getvar (char **ret, const char *name, size_t nlen, void *data)
 {
   struct movemail_getvar_closure *pc = data;
-  
-  if (SEQ ("progname", name, nlen))
-    return mu_program_name;
-  if (SEQ ("source", name, nlen))
-    return pc->source_name;
-  if (SEQ ("dest", name, nlen))
-    return pc->dest_name;
+  const char *s;
 
   if (nlen > 7 && memcmp ("source_", name, 7) == 0)
-    return get_url_part (pc->source_url, name + 7, nlen - 7);
+    return get_url_part (pc->source_url, name + 7, nlen - 7, ret);
+
   if (nlen > 5 && memcmp ("dest_", name, 5) == 0)
-    return get_url_part (pc->dest_url, name + 5, nlen - 5);
+    return get_url_part (pc->dest_url, name + 5, nlen - 5, ret);
   
-  return NULL;
+  if (SEQ ("progname", name, nlen))
+    s = mu_program_name;
+  else if (SEQ ("source", name, nlen))
+    s = pc->source_name;
+  else if (SEQ ("dest", name, nlen))
+    s = pc->dest_name;
+  else
+    return MU_WRDSE_UNDEF;
+    
+  *ret = strdup (s);
+  if (!*ret)
+    return MU_WRDSE_NOSPACE;
+  return MU_WRDSE_OK;
 }
 
 static void
@@ -834,7 +854,6 @@ set_program_id (const char *source_name, const char 
*dest_name)
      plays wise with its argument. We need a mu_set_diag_prefix
      function. */
   mu_program_name = ws.ws_wordv[0];
-  ws.ws_wordv[0] = NULL;
   ws.ws_wordc = 0;
   mu_wordsplit_free (&ws);
   mu_stdstream_strerr_setup (MU_STRERR_STDERR);


hooks/post-receive
-- 
GNU Mailutils



reply via email to

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