[evolution-data-server/evolution-data-server-3-12] Bug #722275 - IMAPX: Incorrectly reads astring values (mailbox names)



commit 94e1402762f806ba31d5207643c8beafe2d10ca4
Author: Milan Crha <mcrha redhat com>
Date:   Thu Apr 10 14:02:59 2014 +0200

    Bug #722275 - IMAPX: Incorrectly reads astring values (mailbox names)

 camel/providers/imapx/camel-imapx-input-stream.c |   56 +++++++++++++++++++++-
 1 files changed, 54 insertions(+), 2 deletions(-)
---
diff --git a/camel/providers/imapx/camel-imapx-input-stream.c 
b/camel/providers/imapx/camel-imapx-input-stream.c
index ebc8af9..555a1a8 100644
--- a/camel/providers/imapx/camel-imapx-input-stream.c
+++ b/camel/providers/imapx/camel-imapx-input-stream.c
@@ -357,14 +357,66 @@ camel_imapx_input_stream_astring (CamelIMAPXInputStream *is,
                                   GError **error)
 {
        camel_imapx_token_t tok;
-       guchar *p, *start;
+       guchar *p, *e, *start, c;
        guint len, inlen;
        gint ret;
 
        g_return_val_if_fail (CAMEL_IMAPX_INPUT_STREAM (is), FALSE);
        g_return_val_if_fail (data != NULL, FALSE);
 
-       tok = camel_imapx_input_stream_token (is, data, &len, cancellable, error);
+       p = is->priv->ptr;
+       e = is->priv->end;
+
+       /* skip whitespace/prefill buffer */
+       do {
+               while (p >= e ) {
+                       is->priv->ptr = p;
+                       if (imapx_input_stream_fill (is, cancellable, error) == IMAPX_TOK_ERROR)
+                               return FALSE;
+                       p = is->priv->ptr;
+                       e = is->priv->end;
+               }
+               c = *p++;
+       } while (c == ' ' || c == '\r');
+
+       if (c == '\"' || c == '{') {
+               tok = camel_imapx_input_stream_token (is, data, &len, cancellable, error);
+       } else {
+               guchar *o, *oe;
+
+               tok = IMAPX_TOK_STRING;
+
+               /* <any %x01-7F except "(){ " / %x00-1F / %x7F > */
+               o = is->priv->tokenbuf;
+               oe = is->priv->tokenbuf + is->priv->bufsize - 1;
+               *o++ = c;
+               while (1) {
+                       while (p < e) {
+                               c = *p++;
+                               if (c <= 0x1f || c == 0x7f || c == '(' || c == ')' || c == '{' || c == ' ') {
+                                       if (c == ' ' || c == '\r')
+                                               is->priv->ptr = p;
+                                       else
+                                               is->priv->ptr = p - 1;
+                                       *o = 0;
+                                       *data = is->priv->tokenbuf;
+                                       return TRUE;
+                               }
+
+                               if (o >= oe) {
+                                       camel_imapx_input_stream_grow (is, 0, &p, &o);
+                                       oe = is->priv->tokenbuf + is->priv->bufsize - 1;
+                                       e = is->priv->end;
+                               }
+                               *o++ = c;
+                       }
+                       is->priv->ptr = p;
+                       if (imapx_input_stream_fill (is, cancellable, error) == IMAPX_TOK_ERROR)
+                               return FALSE;
+                       p = is->priv->ptr;
+                       e = is->priv->end;
+               }
+       }
 
        switch (tok) {
                case IMAPX_TOK_ERROR:


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