]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
oauth2-jwt: Use int64_t instead time_t for portability
authorAki Tuomi <aki.tuomi@open-xchange.com>
Thu, 13 Aug 2020 17:01:41 +0000 (20:01 +0300)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Mon, 29 Mar 2021 12:40:18 +0000 (12:40 +0000)
src/lib-oauth2/oauth2-jwt.c

index 83b241c558ec47440cc7752bd43965df4bf3c5d0..09d39707433e2a3e3f1ec97faf98cdae47d4c88e 100644 (file)
@@ -30,19 +30,26 @@ static const char *get_field(const struct json_tree *tree, const char *key)
        return json_tree_get_value_str(value_node);
 }
 
-static int
-get_time_field(const struct json_tree *tree, const char *key, long *value_r)
+static int get_time_field(const struct json_tree *tree, const char *key,
+                         int64_t *value_r)
 {
+       time_t tvalue;
        const char *value = get_field(tree, key);
        int tz_offset ATTR_UNUSED;
        if (value == NULL)
                return 0;
-       if ((str_to_long(value, value_r) < 0 &&
-            !iso8601_date_parse((const unsigned char*)value, strlen(value),
-                                value_r, &tz_offset)) ||
-           *value_r < 0)
-                return -1;
-       return 1;
+       if (str_to_int64(value, value_r) == 0) {
+               if (*value_r < 0)
+                       return -1;
+               return 1;
+       } else if (iso8601_date_parse((const unsigned char*)value, strlen(value),
+                                     &tvalue, &tz_offset)) {
+               if (tvalue < 0)
+                       return -1;
+               *value_r = tvalue;
+               return 1;
+       }
+       return -1;
 }
 
 static int
@@ -311,9 +318,9 @@ oauth2_jwt_body_process(const struct oauth2_settings *set, const char *alg,
        const char *sub = get_field(tree, "sub");
 
        int ret;
-       long t0 = time(NULL);
+       int64_t t0 = time(NULL);
        /* default IAT and NBF to now */
-       long iat, nbf, exp;
+       int64_t iat, nbf, exp;
        int tz_offset ATTR_UNUSED;
 
        if (sub == NULL) {