commit-mailutils
[Top][All Lists]
Advanced

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

[SCM] GNU Mailutils branch, stream-cleanup, updated. rel-2_1-119-ged83b5


From: Sergey Poznyakoff
Subject: [SCM] GNU Mailutils branch, stream-cleanup, updated. rel-2_1-119-ged83b5a
Date: Fri, 03 Sep 2010 16:21:08 +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=ed83b5a6fec2174efdec37cffa658d7069dc318b

The branch, stream-cleanup has been updated
       via  ed83b5a6fec2174efdec37cffa658d7069dc318b (commit)
       via  ec9510ec415240661bbecff374056162a7380756 (commit)
      from  607f57384987efc9f08a1febff4c6ab00e61e2ab (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 ed83b5a6fec2174efdec37cffa658d7069dc318b
Author: Sergey Poznyakoff <address@hidden>
Date:   Fri Sep 3 16:59:56 2010 +0300

    pop3d: bugfixes.
    
    * pop3d/apop.c (pop3d_apopuser, pop3d_apopuser): Remove statically
    allocated buffers.
    * pop3d/pop3d.c (pop3d_mainloop): Likewise.
    * pop3d/user.c (pop3d_begin_session): Likewise.

commit ec9510ec415240661bbecff374056162a7380756
Author: Sergey Poznyakoff <address@hidden>
Date:   Fri Sep 3 16:08:12 2010 +0300

    pop3d: optimize apop support.
    
    * pop3d/apop.c (pop3d_apopuser): Fix highly ineffective resource
    usage in both branches.
    * pop3d/pop3d.c: Remove misleading comment.

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

Summary of changes:
 pop3d/apop.c  |   92 +++++++++++++++++++++-----------------------------------
 pop3d/pop3d.c |   11 +------
 pop3d/user.c  |   16 ++-------
 3 files changed, 40 insertions(+), 79 deletions(-)

diff --git a/pop3d/apop.c b/pop3d/apop.c
index 632bffb..dca748e 100644
--- a/pop3d/apop.c
+++ b/pop3d/apop.c
@@ -41,11 +41,11 @@
 char *
 pop3d_apopuser (const char *user)
 {
-  char *password;
-  char buf[POP_MAXCMDLEN];
-
+  char *password = NULL;
+  
 #ifdef USE_DBM
   {
+    size_t len;
     DBM_FILE db;
     DBM_DATUM key, data;
 
@@ -60,11 +60,8 @@ pop3d_apopuser (const char *user)
     memset (&key, 0, sizeof key);
     memset (&data, 0, sizeof data);
 
-    strncpy (buf, user, sizeof buf);
-    /* strncpy () is lame and does not NULL terminate.  */
-    buf[sizeof (buf) - 1] = '\0';
-    MU_DATUM_PTR(key) = buf;
-    MU_DATUM_SIZE(key) = strlen (buf);
+    MU_DATUM_PTR (key) = (void*) user;
+    MU_DATUM_SIZE (key) = strlen (user);
 
     rc = mu_dbm_fetch (db, key, &data);
     mu_dbm_close (db);
@@ -74,21 +71,23 @@ pop3d_apopuser (const char *user)
                        _("cannot fetch APOP data: %s"), mu_strerror (errno));
        return NULL;
       }
-    password = calloc (MU_DATUM_SIZE(data) + 1, sizeof (*password));
+    len = MU_DATUM_SIZE (data);
+    password = malloc (len + 1);
     if (password == NULL)
       {
        mu_dbm_datum_free (&data);
        return NULL;
       }
-    
-    sprintf (password, "%.*s", (int) MU_DATUM_SIZE(data),
-            (char*) MU_DATUM_PTR(data));
+    memcpy (password, MU_DATUM_PTR (data), len);
+    password[len] = 0;
     mu_dbm_datum_free (&data);
     return password;
   }
 #else /* !USE_DBM */
   {
-    char *tmp;
+    char *buf = NULL;
+    size_t size = 0;
+    size_t ulen;
     FILE *apop_file;
 
     if (mu_check_perm (APOP_PASSFILE, 0600))
@@ -101,44 +100,32 @@ pop3d_apopuser (const char *user)
     apop_file = fopen (APOP_PASSFILE, "r");
     if (apop_file == NULL)
       {
-       mu_diag_output (MU_DIAG_INFO, _("unable to open APOP password file %s"),
-               strerror (errno));
+       mu_diag_output (MU_DIAG_INFO,
+                       _("unable to open APOP password file %s: %s"),
+                       APOP_PASSFILE, mu_strerror (errno));
        return NULL;
       }
 
-    password = calloc (APOP_DIGEST, sizeof (*password));
-    if (password == NULL)
+    ulen = strlen (user);
+    while (getline (&buf, &size, apop_file) > 0)
       {
-       fclose (apop_file);
-       pop3d_abquit (ERR_NO_MEM);
-      }
+       char *p, *start = mu_str_stripws (buf);
 
-    while (fgets (buf, sizeof (buf) - 1, apop_file) != NULL)
-      {
-       tmp = strchr (buf, ':');
-       if (tmp == NULL)
+       if (!*start || *start == '#')
          continue;
-       *tmp++ = '\0';
-
-       if (strncmp (user, buf, strlen (user)))
+       p = strchr (start, ':');
+       if (!p)
          continue;
-
-       strncpy (password, tmp, APOP_DIGEST);
-       /* strncpy () is lame and does not NULL terminate.  */
-       password[APOP_DIGEST - 1] = '\0';
-       tmp = strchr (password, '\n');
-       if (tmp)
-         *tmp = '\0';
-       break;
+       if (p - start == ulen && memcmp (user, start, ulen) == 0)
+         {
+           p = mu_str_skip_class (p + 1, MU_CTYPE_SPACE);
+           if (*p)
+             password = strdup (p);
+           break;
+         }
       }
 
     fclose (apop_file);
-    if (*password == '\0')
-      {
-       free (password);
-       return NULL;
-      }
-
     return password;
   }
 #endif
@@ -147,11 +134,12 @@ pop3d_apopuser (const char *user)
 int
 pop3d_apop (char *arg)
 {
-  char *tmp, *password, *user_digest, *user;
-  char buf[POP_MAXCMDLEN];
+  char *p, *password, *user_digest, *user;
   struct mu_md5_ctx md5context;
   unsigned char md5digest[16];
-
+  char buf[2 * 16 + 1];
+  size_t i;
+  
   if (state != AUTHORIZATION)
     return ERR_WRONG_STATE;
 
@@ -159,11 +147,6 @@ pop3d_apop (char *arg)
     return ERR_BAD_ARGS;
 
   pop3d_parse_command (arg, &user, &user_digest);
-  if (strlen (user) > (POP_MAXCMDLEN - APOP_DIGEST))
-    {
-      mu_diag_output (MU_DIAG_INFO, _("user name too long: %s"), user);
-      return ERR_BAD_ARGS;
-    }
 
   password = pop3d_apopuser (user);
   if (password == NULL)
@@ -180,14 +163,9 @@ pop3d_apop (char *arg)
   free (password);
   mu_md5_finish_ctx (&md5context, md5digest);
 
-  {
-    int i;
-    tmp = buf;
-    for (i = 0; i < 16; i++, tmp += 2)
-      sprintf (tmp, "%02x", md5digest[i]);
-  }
-
-  *tmp++ = '\0';
+  for (i = 0, p = buf; i < 16; i++, p += 2)
+      sprintf (p, "%02x", md5digest[i]);
+  *p = 0;
 
   if (strcmp (user_digest, buf))
     {
diff --git a/pop3d/pop3d.c b/pop3d/pop3d.c
index 5a09efc..6b70f55 100644
--- a/pop3d/pop3d.c
+++ b/pop3d/pop3d.c
@@ -261,11 +261,6 @@ pop3d_mainloop (int fd, FILE *infile, FILE *outfile)
       buf = pop3d_readline (buffer, sizeof (buffer));
       pop3d_parse_command (buf, &cmd, &arg);
 
-      /* The mailbox size needs to be check to make sure that we are in
-        sync.  Some other applications may not respect the *.lock or
-        the lock may be stale because downloading on slow modem.
-        We rely on the size of the mailbox for the check and bail if out
-        of sync.  */
       if (state == TRANSACTION && !mu_mailbox_is_updated (mbox))
        {
          static mu_off_t mailbox_size;
@@ -281,11 +276,7 @@ pop3d_mainloop (int fd, FILE *infile, FILE *outfile)
       /* Refresh the Lock.  */
       pop3d_touchlock ();
 
-      if (strlen (arg) > POP_MAXCMDLEN || strlen (cmd) > POP_MAXCMDLEN)
-       status = ERR_TOO_LONG;
-      else if (strlen (cmd) > 4)
-       status = ERR_BAD_CMD;
-      else if ((handler = pop3d_find_command (cmd)) != NULL)
+      if ((handler = pop3d_find_command (cmd)) != NULL)
        status = handler (arg);
       else
        status = ERR_BAD_CMD;
diff --git a/pop3d/user.c b/pop3d/user.c
index 6d0ef3f..cbe8c41 100644
--- a/pop3d/user.c
+++ b/pop3d/user.c
@@ -89,7 +89,7 @@ pop3d_begin_session ()
 int
 pop3d_user (char *arg)
 {
-  char *buf, pass[POP_MAXCMDLEN], *tmp, *cmd;
+  char *buf, *pass, *cmd;
   char buffer[512];
   
   if (state != AUTHORIZATION)
@@ -102,16 +102,7 @@ pop3d_user (char *arg)
   pop3d_flush_output ();
 
   buf = pop3d_readline (buffer, sizeof (buffer));
-  pop3d_parse_command (buf, &cmd, &tmp);
-
-  if (strlen (tmp) > POP_MAXCMDLEN)
-    return ERR_TOO_LONG;
-  else
-    {
-      strncpy (pass, tmp, POP_MAXCMDLEN);
-      /* strncpy () is lame, make sure the string is null terminated.  */
-      pass[POP_MAXCMDLEN - 1] = '\0';
-    }
+  pop3d_parse_command (buf, &cmd, &pass);
 
   if (mu_c_strcasecmp (cmd, "PASS") == 0)
     {
@@ -122,7 +113,8 @@ pop3d_user (char *arg)
       tmp = pop3d_apopuser (arg);
       if (tmp != NULL)
        {
-         mu_diag_output (MU_DIAG_INFO, _("APOP user %s tried to log in with 
USER"), arg);
+         mu_diag_output (MU_DIAG_INFO,
+                         _("APOP user %s tried to log in with USER"), arg);
          return ERR_BAD_LOGIN;
        }
 #endif


hooks/post-receive
-- 
GNU Mailutils



reply via email to

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