Commit ab651950 ab651950ab94c6c8e228b42897abb38a83351b23 by Sergey Poznyakoff

imap4d: fix reading multi-line literals

* imap4d/io.c (imap4d_tokbuf_decrlf): New function.
(imap4d_tokbuf_expand): Call imap4d_tokbuf_decrlf for
literals.
1 parent 39b00209
...@@ -416,6 +416,25 @@ imap4d_tokbuf_unquote (struct imap4d_tokbuf *tok, size_t *poff, size_t *plen) ...@@ -416,6 +416,25 @@ imap4d_tokbuf_unquote (struct imap4d_tokbuf *tok, size_t *poff, size_t *plen)
416 } 416 }
417 417
418 static void 418 static void
419 imap4d_tokbuf_decrlf (struct imap4d_tokbuf *tok, size_t off, size_t *plen)
420 {
421 char *buf = tok->buffer + off;
422 size_t len = *plen;
423 char *p, *end = buf + len;
424
425 for (p = end - 1; p > buf; p--)
426 {
427 if (*p == '\n' && p > buf && p[-1] == '\r')
428 {
429 memmove (p - 1, p, end - p);
430 end--;
431 p--;
432 }
433 }
434 *plen = end - buf;
435 }
436
437 static void
419 imap4d_tokbuf_expand (struct imap4d_tokbuf *tok, size_t size) 438 imap4d_tokbuf_expand (struct imap4d_tokbuf *tok, size_t size)
420 { 439 {
421 if (tok->size - tok->level < size) 440 if (tok->size - tok->level < size)
...@@ -596,6 +615,7 @@ imap4d_readline (struct imap4d_tokbuf *tok) ...@@ -596,6 +615,7 @@ imap4d_readline (struct imap4d_tokbuf *tok)
596 } 615 }
597 check_input_err (rc, len); 616 check_input_err (rc, len);
598 imap4d_tokbuf_unquote (tok, &off, &len); 617 imap4d_tokbuf_unquote (tok, &off, &len);
618 imap4d_tokbuf_decrlf (tok, off, &len);
599 tok->level += len; 619 tok->level += len;
600 tok->buffer[tok->level++] = 0; 620 tok->buffer[tok->level++] = 0;
601 tok->argp[tok->argc - 1] = off; 621 tok->argp[tok->argc - 1] = off;
......