From: Timo Sirainen Date: Thu, 12 Nov 2009 17:42:31 +0000 (-0500) Subject: rfc2231 parser: Fixed parsing "key*". X-Git-Tag: 2.0.beta1~166 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ec23a602b0230eea29e64e2f283a9cf215be1f82;p=thirdparty%2Fdovecot%2Fcore.git rfc2231 parser: Fixed parsing "key*". --HG-- branch : HEAD --- diff --git a/src/lib-mail/rfc2231-parser.c b/src/lib-mail/rfc2231-parser.c index 9d35d4b86e..3762eaeb66 100644 --- a/src/lib-mail/rfc2231-parser.c +++ b/src/lib-mail/rfc2231-parser.c @@ -67,11 +67,14 @@ int rfc2231_parse(struct rfc822_parser_context *ctx, } p = strchr(key, '*'); if (p != NULL) { - p2 = p++; - rfc2231_param.idx = 0; - for (; *p >= '0' && *p <= '9'; p++) { - rfc2231_param.idx = - rfc2231_param.idx*10 + *p - '0'; + p2 = p; + if (p[1] != '\0') { + p++; + rfc2231_param.idx = 0; + for (; *p >= '0' && *p <= '9'; p++) { + rfc2231_param.idx = + rfc2231_param.idx*10 + *p - '0'; + } } if (*p != '*') rfc2231_param.extended = FALSE; diff --git a/src/lib-mail/test-rfc2231-parser.c b/src/lib-mail/test-rfc2231-parser.c index c8164d26a3..d65f401b93 100644 --- a/src/lib-mail/test-rfc2231-parser.c +++ b/src/lib-mail/test-rfc2231-parser.c @@ -8,6 +8,7 @@ static void test_rfc2231_parser(void) { const char *input = + "; key4*=us-ascii''foo" "; key*2=ba%" "; key2*0=a" "; key3*0*=us-ascii'en'xyz" @@ -22,26 +23,21 @@ static void test_rfc2231_parser(void) "''ab%25", "key3*", "us-ascii'en'xyzplop%25", + "key4*", + "us-ascii''foo", NULL }; struct rfc822_parser_context parser; const char *const *result; unsigned int i; - bool success; + test_begin("rfc2231 parser"); rfc822_parser_init(&parser, (const void *)input, strlen(input), NULL); - if (rfc2231_parse(&parser, &result) < 0) - success = FALSE; - else { - success = TRUE; - for (i = 0; output[i] != NULL && result[i] != NULL; i++) { - if (strcmp(output[i], result[i]) != 0) - break; - } - if (output[i] != NULL || result[i] != NULL) - success = FALSE; - } - test_out("rfc2231_parse()", success); + test_assert(rfc2231_parse(&parser, &result) == 0); + for (i = 0; output[i] != NULL && result[i] != NULL; i++) + test_assert(strcmp(output[i], result[i]) == 0); + test_assert(output[i] == NULL && result[i] == NULL); + test_end(); } int main(void)