[gmime: 21/23] Fix parsing timezone "-0001"



commit cde20050600a6ad55604c0378e6bcc88ed0c42f2
Author: Jakub Wilk <jwilk jwilk net>
Date:   Sat Oct 28 22:09:41 2017 +0200

    Fix parsing timezone "-0001"
    
    decode_int() returned -1 on error; so it was impossible to distinguish
    between error and correctly parsed number -1. As a consequence, the
    timezone "-0001" (which is unusual, but RFC-compliant) was rejected as
    incorrect.

 gmime/gmime-utils.c |   11 +----------
 tests/test-mime.c   |    3 +++
 2 files changed, 4 insertions(+), 10 deletions(-)
---
diff --git a/gmime/gmime-utils.c b/gmime/gmime-utils.c
index f21e8d5..7325c79 100644
--- a/gmime/gmime-utils.c
+++ b/gmime/gmime-utils.c
@@ -295,13 +295,6 @@ decode_int (const char *in, size_t inlen)
        inptr = in;
        inend = in + inlen;
        
-       if (*inptr == '-') {
-               sign = -1;
-               inptr++;
-       } else if (*inptr == '+') {
-               inptr++;
-       }
-       
        while (inptr < inend) {
                if (!(*inptr >= '0' && *inptr <= '9'))
                        return -1;
@@ -311,8 +304,6 @@ decode_int (const char *in, size_t inlen)
                inptr++;
        }
        
-       val *= sign;
-       
        return val;
 }
 
@@ -473,7 +464,7 @@ get_tzone (date_token **token)
                        continue;
                
                if (len == 5 && (*inptr == '+' || *inptr == '-')) {
-                       if ((value = decode_int (inptr, len)) == -1)
+                       if ((value = decode_int (inptr + 1, len - 1)) == -1)
                                return NULL;
                        
                        memcpy (tzone, inptr, len);
diff --git a/tests/test-mime.c b/tests/test-mime.c
index 246cd0e..4ad1329 100644
--- a/tests/test-mime.c
+++ b/tests/test-mime.c
@@ -336,6 +336,9 @@ static struct {
        { "17-6-2008 17:10:08",
          "Tue, 17 Jun 2008 17:10:08 +0000",
          1213722608, 0 },
+       { "Sat, 28 Oct 2017 19:41:29 -0001",
+         "Sat, 28 Oct 2017 19:41:29 -0001",
+         1509219749, -1 },
        { "nonsense",
          "Thu, 01 Jan 1970 00:00:00 +0000",
          0, 0 }


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