]> code.citadel.org Git - citadel.git/blobdiff - citadel/modules/imap/imap_tools.c
fix possible buffer underrun (by 1;-)
[citadel.git] / citadel / modules / imap / imap_tools.c
index 28fb95948eca6528f339ecb46da41449b876f36c..e3cc6bffce11a878c15b5f25e8783ae4c51ccd89 100644 (file)
@@ -4,7 +4,7 @@
  * Copyright (c) 2001-2009 by the citadel.org team and others, except for
  * most of the UTF7 and UTF8 handling code which was lifted from Evolution.
  *
- * This program is free software; you can redistribute it and/or modify
+ * This program is open source software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 3 of the License, or
  * (at your option) any later version.
@@ -225,7 +225,7 @@ static char* toimap(char* destp, char* destend, char* src)
 
        *destp = 0;
        string_init(&dest, destp, destend-destp);
-       /* syslog(LOG_DEBUG, "toimap %s\r\n", src); */
+       /* IMAP_syslog(LOG_DEBUG, "toimap %s", src); */
 
        for (;;)
        {
@@ -291,7 +291,7 @@ static char* toimap(char* destp, char* destend, char* src)
 
        if (state == 1)
                utf7_closeb64(&dest, v, i);
-       /* syslog(LOG_DEBUG, "    -> %s\r\n", destp); */
+       /* IMAP_syslog(LOG_DEBUG, "    -> %s", destp); */
        return string_end(&dest);
 }
 
@@ -309,7 +309,7 @@ static char* fromimap(char* destp, char* destend, const char* src)
 
        *destp = 0;
        string_init(&dest, destp, destend-destp);
-       /* syslog(LOG_DEBUG, "fromimap %s\r\n", src); */
+       /* IMAP_syslog(LOG_DEBUG, "fromimap %s", src); */
 
        do {
                c = *p++;
@@ -367,7 +367,7 @@ static char* fromimap(char* destp, char* destend, const char* src)
                        }
        } while (c != '\0');
 
-       /* syslog(LOG_DEBUG, "      -> %s\r\n", destp); */
+       /* IMAP_syslog(LOG_DEBUG, "      -> %s", destp); */
        return string_end(&dest);
 }
 
@@ -569,13 +569,13 @@ void imap_mailboxname(char *buf, int bufsize, struct ctdlroom *qrbuf)
        if (qrbuf->QRflags & QR_MAILBOX)
        {
                if (strcasecmp(qrbuf->QRname+11, MAILROOM) == 0)
-                       p = toimap(p, bufend, "INBOX");
+                       toimap(p, bufend, "INBOX");
                else
                {
                        p = toimap(p, bufend, "INBOX");
                        if (p < bufend)
                                *p++ = '/';
-                       p = toimap(p, bufend, qrbuf->QRname+11);
+                       toimap(p, bufend, qrbuf->QRname+11);
                }
        }
        else
@@ -586,7 +586,7 @@ void imap_mailboxname(char *buf, int bufsize, struct ctdlroom *qrbuf)
                p = toimap(p, bufend, fl->f_name);
                if (p < bufend)
                        *p++ = '/';
-               p = toimap(p, bufend, qrbuf->QRname);
+               toimap(p, bufend, qrbuf->QRname);
        }
 }
 
@@ -604,6 +604,7 @@ void imap_mailboxname(char *buf, int bufsize, struct ctdlroom *qrbuf)
 
 int imap_roomname(char *rbuf, int bufsize, const char *foldername)
 {
+       struct CitContext *CCC = CC;
        int levels;
        char floorname[ROOMNAMELEN*2];
        char roomname[ROOMNAMELEN];
@@ -680,7 +681,7 @@ int imap_roomname(char *rbuf, int bufsize, const char *foldername)
        ret = (0 | IR_MAILBOX);
 
 exit:
-       syslog(LOG_DEBUG, "(That translates to \"%s\")\n", rbuf);
+       IMAP_syslog(LOG_DEBUG, "(That translates to \"%s\")", rbuf);
        return(ret);
 }
 
@@ -839,7 +840,10 @@ star:
                                }
                                return WILDMAT_TRUE;
                        }
-                       while (!IsEmptyStr(text) && (*(text - 1) != WILDMAT_DELIM)) {
+                       while (!IsEmptyStr(text) &&
+                              /* make shure texst - 1 isn't before lcase_p */
+                              ((text == lcase_text) || (*(text - 1) != WILDMAT_DELIM)))
+                       {
                                if ((matched = do_imap_match(text++, p))
                                   != WILDMAT_FALSE) {
                                        return matched;