]> code.citadel.org Git - citadel.git/blobdiff - citadel/server/modules/imap/imap_list.c
IMAP memory issues with use of ConstStr
[citadel.git] / citadel / server / modules / imap / imap_list.c
index 7565d8e94bb37ad3e5d2047609d52b042ef1a82f..33b714912ea767506f3002ed259a1dfe32c5f267 100644 (file)
@@ -236,14 +236,16 @@ void imap_list(int num_parms, ConstStr *Params)
         * selection options.  Extract their exact position, and then modify our
         * expectation of where the root folder will be specified.
         */
-       if (Params[2].Key[0] == '(') {
+       if (Params[2].len && (Params[2].Key[0] == '(')) {
                extended_list_in_use = 1;
                selection_left = 2;
                paren_nest = 0;
                for (i=2; i<num_parms; ++i) {
-                       for (j=0; Params[i].Key[j]; ++j) {
-                               if (Params[i].Key[j] == '(') ++paren_nest;
-                               if (Params[i].Key[j] == ')') --paren_nest;
+                       if (Params[i].len) {
+                               for (j=0; Params[i].Key[j]; ++j) {
+                                       if (Params[i].Key[j] == '(') ++paren_nest;
+                                       if (Params[i].Key[j] == ')') --paren_nest;
+                               }
                        }
                        if (paren_nest == 0) {
                                selection_right = i;    /* found end of selection options */
@@ -258,12 +260,12 @@ void imap_list(int num_parms, ConstStr *Params)
        if ((selection_left > 0) && (selection_right >= selection_left)) {
 
                /* Strip off the outer parentheses */
-               if (Params[selection_left].Key[0] == '(') {
+               if (Params[selection_left].len && (Params[selection_left].Key[0] == '(')) {
                        TokenCutLeft(&Imap->Cmd, 
                                     &Params[selection_left], 
                                     1);
                }
-               if (Params[selection_right].Key[Params[selection_right].len-1] == ')') {
+               if (Params[selection_right].len && (Params[selection_right].Key[Params[selection_right].len-1] == ')')) {
                        TokenCutRight(&Imap->Cmd, 
                                      &Params[selection_right], 
                                      1);
@@ -293,13 +295,15 @@ void imap_list(int num_parms, ConstStr *Params)
        patterns_left = root_pos + 1;
        patterns_right = root_pos + 1;
 
-       if (Params[patterns_left].Key[0] == '(') {
+       if (Params[patterns_left].len && (Params[patterns_left].Key[0] == '(')) {
                extended_list_in_use = 1;
                paren_nest = 0;
                for (i=patterns_left; i<num_parms; ++i) {
-                       for (j=0; &Params[i].Key[j]; ++j) {
-                               if (Params[i].Key[j] == '(') ++paren_nest;
-                               if (Params[i].Key[j] == ')') --paren_nest;
+                       if (Params[i].len) {
+                               for (j=0; Params[i].Key[j]; ++j) {
+                                       if (Params[i].Key[j] == '(') ++paren_nest;
+                                       if (Params[i].Key[j] == ')') --paren_nest;
+                               }
                        }
                        if (paren_nest == 0) {
                                patterns_right = i;     /* found end of patterns */
@@ -352,29 +356,31 @@ void imap_list(int num_parms, ConstStr *Params)
                extended_list_in_use = 1;
                paren_nest = 0;
                for (i=return_left; i<num_parms; ++i) {
-                       for (j=0;   Params[i].Key[j]; ++j) {
-                               if (Params[i].Key[j] == '(') ++paren_nest;
-                               if (Params[i].Key[j] == ')') --paren_nest;
-                       }
+                       if (Params[i].len) {
+                               for (j=0;   Params[i].Key[j]; ++j) {
+                                       if (Params[i].Key[j] == '(') ++paren_nest;
+                                       if (Params[i].Key[j] == ')') --paren_nest;
+                               }
 
-                       /* Might as well look for these while we're in here... */
-                       if (Params[i].Key[0] == '(') 
-                               TokenCutLeft(&Imap->Cmd, 
-                                            &Params[i], 
-                                            1);
-                       if (Params[i].Key[Params[i].len-1] == ')')
-                           TokenCutRight(&Imap->Cmd, 
-                                         &Params[i], 
-                                         1);
+                               /* Might as well look for these while we're in here... */
+                               if (Params[i].Key[0] == '(') 
+                                       TokenCutLeft(&Imap->Cmd, 
+                                               &Params[i], 
+                                               1);
+                               if (Params[i].len && (Params[i].Key[Params[i].len-1] == ')'))
+                               TokenCutRight(&Imap->Cmd, 
+                                               &Params[i], 
+                                               1);
 
-                       syslog(LOG_DEBUG, "evaluating <%s>", Params[i].Key);
+                               syslog(LOG_DEBUG, "evaluating <%s>", Params[i].Key);
 
-                       if (!strcasecmp(Params[i].Key, "SUBSCRIBED")) {
-                               ImapFilter.return_subscribed = 1;
-                       }
+                               if (!strcasecmp(Params[i].Key, "SUBSCRIBED")) {
+                                       ImapFilter.return_subscribed = 1;
+                               }
 
-                       else if (!strcasecmp(Params[i].Key, "CHILDREN")) {
-                               ImapFilter.return_children = 1;
+                               else if (!strcasecmp(Params[i].Key, "CHILDREN")) {
+                                       ImapFilter.return_children = 1;
+                               }
                        }
 
                        if (paren_nest == 0) {