test/x509_time_test.c:286: error: BUFFER_OVERRUN_L3
  Offset: [1, +oo] Size: [0, +oo] by call to `X509_cmp_time`.
Showing all 17 steps of the trace


test/x509_time_test.c:283:19: Call
281.       int cmp_result, failed = 0;
282.   
283.       asn1_before = ASN1_TIME_adj(NULL, now, -1, 0);
                         ^
284.       asn1_after = ASN1_TIME_adj(NULL, now, 1, 0);
285.   

crypto/asn1/a_time.c:318:1: Parameter `*s->data`
  316.   }
  317.   
  318. > ASN1_TIME *ASN1_TIME_adj(ASN1_TIME *s, time_t t,
  319.                            int offset_day, long offset_sec)
  320.   {

test/x509_time_test.c:284:18: Call
282.   
283.       asn1_before = ASN1_TIME_adj(NULL, now, -1, 0);
284.       asn1_after = ASN1_TIME_adj(NULL, now, 1, 0);
                        ^
285.   
286.       cmp_result  = X509_cmp_time(asn1_before, NULL);

crypto/asn1/a_time.c:318:1: Parameter `*s->data`
  316.   }
  317.   
  318. > ASN1_TIME *ASN1_TIME_adj(ASN1_TIME *s, time_t t,
  319.                            int offset_day, long offset_sec)
  320.   {

test/x509_time_test.c:286:19: Call
284.       asn1_after = ASN1_TIME_adj(NULL, now, 1, 0);
285.   
286.       cmp_result  = X509_cmp_time(asn1_before, NULL);
                         ^
287.       if (!TEST_int_eq(cmp_result, -1))
288.           failed = 1;

crypto/x509/x509_vfy.c:1756:1: Parameter `*ctm->data`
  1754.   }
  1755.   
  1756. > int X509_cmp_time(const ASN1_TIME *ctm, time_t *cmp_time)
  1757.   {
  1758.       static const size_t utctime_length = sizeof("YYMMDDHHMMSSZ") - 1;

crypto/x509/x509_vfy.c:1807:10: Call
  1805.       if (asn1_cmp_time == NULL)
  1806.           goto err;
  1807.       if (!ASN1_TIME_diff(&day, &sec, ctm, asn1_cmp_time))
                   ^
  1808.           goto err;
  1809.   

crypto/asn1/a_time.c:448:1: Parameter `*from->data`
    446.   }
    447.   
    448. > int ASN1_TIME_diff(int *pday, int *psec,
    449.                      const ASN1_TIME *from, const ASN1_TIME *to)
    450.   {

crypto/asn1/a_time.c:453:10: Call
    451.       struct tm tm_from, tm_to;
    452.   
    453.       if (!ASN1_TIME_to_tm(from, &tm_from))
                    ^
    454.           return 0;
    455.       if (!ASN1_TIME_to_tm(to, &tm_to))

crypto/asn1/a_time.c:433:1: Parameter `*s->data`
      431.   }
      432.   
      433. > int ASN1_TIME_to_tm(const ASN1_TIME *s, struct tm *tm)
      434.   {
      435.       if (s == NULL) {

crypto/asn1/a_time.c:445:12: Call
      443.       }
      444.   
      445.       return asn1_time_to_tm(tm, s);
                        ^
      446.   }
      447.   

crypto/asn1/a_time.c:80:5: <Offset trace>
78.       static const int mdays[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
79.       char *a;
80.       int n, i, i2, l, o, min_l = 11, strict = 0, end = 6, btz = 5, md;
          ^
81.       struct tm tmp;
82.   

crypto/asn1/a_time.c:80:5: Assignment
        78.       static const int mdays[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
        79.       char *a;
        80.       int n, i, i2, l, o, min_l = 11, strict = 0, end = 6, btz = 5, md;
                  ^
        81.       struct tm tmp;
        82.   

crypto/asn1/a_time.c:74:1: <Length trace>
72.   }
73.   
74. > int asn1_time_to_tm(struct tm *tm, const ASN1_TIME *d)
75.   {
76.       static const int min[9] = { 0, 0, 1, 1, 0, 0, 0, 0, 0 };

crypto/asn1/a_time.c:74:1: Parameter `*d->data`
        72.   }
        73.   
        74. > int asn1_time_to_tm(struct tm *tm, const ASN1_TIME *d)
        75.   {
        76.       static const int min[9] = { 0, 0, 1, 1, 0, 0, 0, 0, 0 };

crypto/asn1/a_time.c:110:5: Assignment
        108.   
        109.       l = d->length;
        110.       a = (char *)d->data;
                   ^
        111.       o = 0;
        112.       memset(&tmp, 0, sizeof(tmp));

crypto/asn1/a_time.c:134:14: Array access: Offset: [1, +oo] Size: [0, +oo] by call to `X509_cmp_time` 
        132.               goto err;
        133.   
        134.           if (!ossl_isdigit(a[o]))
                            ^
        135.               goto err;
        136.           n = (n * 10) + a[o] - '0';

int asn1_time_to_tm(struct tm *tm, const ASN1_TIME *d)
{
    static const int min[9] = { 0, 0, 1, 1, 0, 0, 0, 0, 0 };
    static const int max[9] = { 99, 99, 12, 31, 23, 59, 59, 12, 59 };
    static const int mdays[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
    char *a;
    int n, i, i2, l, o, min_l = 11, strict = 0, end = 6, btz = 5, md;
    struct tm tmp;
    if (d->type == V_ASN1_UTCTIME) {
        if (d->flags & ASN1_STRING_FLAG_X509_TIME) {
            min_l = 13;
            strict = 1;
        }
    } else if (d->type == V_ASN1_GENERALIZEDTIME) {
        end = 7;
        btz = 6;
        if (d->flags & ASN1_STRING_FLAG_X509_TIME) {
            min_l = 15;
            strict = 1;
        } else {
            min_l = 13;
        }
    } else {
        return 0;
    }
    l = d->length;
    a = (char *)d->data;
    o = 0;
    memset(&tmp, 0, sizeof(tmp));
    if (l < min_l)
        goto err;
    for (i = 0; i < end; i++) {
        if (!strict && (i == btz) && ((a[o] == 'Z') || (a[o] == '+') || (a[o] == '-'))) {
            i++;
            break;
        }
        if (!ossl_isdigit(a[o]))
            goto err;
        n = a[o] - '0';
        if (++o == l)
            goto err;
        if (!ossl_isdigit(a[o]))
            goto err;
        n = (n * 10) + a[o] - '0';
        if (++o == l)
            goto err;
        i2 = (d->type == V_ASN1_UTCTIME) ? i + 1 : i;
        if ((n < min[i2]) || (n > max[i2]))
            goto err;
        switch (i2) {
        case 0:
            tmp.tm_year = n * 100 - 1900;
            break;
        case 1:
            if (d->type == V_ASN1_UTCTIME)
                tmp.tm_year = n < 50 ? n + 100 : n;
            else
                tmp.tm_year += n;
            break;
        case 2:
            tmp.tm_mon = n - 1;
            break;
        case 3:
            if (tmp.tm_mon == 1) {
                md = mdays[1] + leap_year(tmp.tm_year + 1900);
            } else {
                md = mdays[tmp.tm_mon];
            }
            if (n > md)
                goto err;
            tmp.tm_mday = n;
            determine_days(&tmp);
            break;
        case 4:
            tmp.tm_hour = n;
            break;
        case 5:
            tmp.tm_min = n;
            break;
        case 6:
            tmp.tm_sec = n;
            break;
        }
    }
    if (d->type == V_ASN1_GENERALIZEDTIME && a[o] == '.') {
        if (strict)
            goto err;
        if (++o == l)
            goto err;
        i = o;
        while ((o < l) && ossl_isdigit(a[o]))
            o++;
        if (i == o)
            goto err;
        if (o == l)
            goto err;
    }
    if (a[o] == 'Z') {
        o++;
    } else if (!strict && ((a[o] == '+') || (a[o] == '-'))) {
        int offsign = a[o] == '-' ? 1 : -1;
        int offset = 0;
        o++;
        if (o + 4 != l)
            goto err;
        for (i = end; i < end + 2; i++) {
            if (!ossl_isdigit(a[o]))
                goto err;
            n = a[o] - '0';
            o++;
            if (!ossl_isdigit(a[o]))
                goto err;
            n = (n * 10) + a[o] - '0';
            i2 = (d->type == V_ASN1_UTCTIME) ? i + 1 : i;
            if ((n < min[i2]) || (n > max[i2]))
                goto err;
            if (tm != NULL) {
                if (i == end)
                    offset = n * 3600;
                else if (i == end + 1)
                    offset += n * 60;
            }
            o++;
        }
        if (offset && !OPENSSL_gmtime_adj(&tmp, 0, offset * offsign))
            goto err;
    } else {
        goto err;
    }
    if (o == l) {
        if (tm != NULL)
            *tm = tmp;
        return 1;
    }
 err:
    return 0;
}
['static int test_x509_cmp_time_current(void)\n{\n    time_t now = time(NULL);\n    ASN1_TIME *asn1_before = NULL, *asn1_after = NULL;\n    int cmp_result, failed = 0;\n    asn1_before = ASN1_TIME_adj(NULL, now, -1, 0);\n    asn1_after = ASN1_TIME_adj(NULL, now, 1, 0);\n    cmp_result  = X509_cmp_time(asn1_before, NULL);\n    if (!TEST_int_eq(cmp_result, -1))\n        failed = 1;\n    cmp_result = X509_cmp_time(asn1_after, NULL);\n    if (!TEST_int_eq(cmp_result, 1))\n        failed = 1;\n    ASN1_TIME_free(asn1_before);\n    ASN1_TIME_free(asn1_after);\n    return failed == 0;\n}', 'ASN1_TIME *ASN1_TIME_adj(ASN1_TIME *s, time_t t,\n                         int offset_day, long offset_sec)\n{\n    struct tm *ts;\n    struct tm data;\n    ts = OPENSSL_gmtime(&t, &data);\n    if (ts == NULL) {\n        ASN1err(ASN1_F_ASN1_TIME_ADJ, ASN1_R_ERROR_GETTING_TIME);\n        return NULL;\n    }\n    if (offset_day || offset_sec) {\n        if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec))\n            return NULL;\n    }\n    return asn1_time_from_tm(s, ts, V_ASN1_UNDEF);\n}', 'int X509_cmp_time(const ASN1_TIME *ctm, time_t *cmp_time)\n{\n    static const size_t utctime_length = sizeof("YYMMDDHHMMSSZ") - 1;\n    static const size_t generalizedtime_length = sizeof("YYYYMMDDHHMMSSZ") - 1;\n    ASN1_TIME *asn1_cmp_time = NULL;\n    int i, day, sec, ret = 0;\n    switch (ctm->type) {\n    case V_ASN1_UTCTIME:\n        if (ctm->length != (int)(utctime_length))\n            return 0;\n        break;\n    case V_ASN1_GENERALIZEDTIME:\n        if (ctm->length != (int)(generalizedtime_length))\n            return 0;\n        break;\n    default:\n        return 0;\n    }\n    for (i = 0; i < ctm->length - 1; i++) {\n        if (!ossl_isdigit(ctm->data[i]))\n            return 0;\n    }\n    if (ctm->data[ctm->length - 1] != \'Z\')\n        return 0;\n    asn1_cmp_time = X509_time_adj(NULL, 0, cmp_time);\n    if (asn1_cmp_time == NULL)\n        goto err;\n    if (!ASN1_TIME_diff(&day, &sec, ctm, asn1_cmp_time))\n        goto err;\n    ret = (day >= 0 && sec >= 0) ? -1 : 1;\n err:\n    ASN1_TIME_free(asn1_cmp_time);\n    return ret;\n}', 'int ASN1_TIME_diff(int *pday, int *psec,\n                   const ASN1_TIME *from, const ASN1_TIME *to)\n{\n    struct tm tm_from, tm_to;\n    if (!ASN1_TIME_to_tm(from, &tm_from))\n        return 0;\n    if (!ASN1_TIME_to_tm(to, &tm_to))\n        return 0;\n    return OPENSSL_gmtime_diff(pday, psec, &tm_from, &tm_to);\n}', 'int ASN1_TIME_to_tm(const ASN1_TIME *s, struct tm *tm)\n{\n    if (s == NULL) {\n        time_t now_t;\n        time(&now_t);\n        memset(tm, 0, sizeof(*tm));\n        if (OPENSSL_gmtime(&now_t, tm) != NULL)\n            return 1;\n        return 0;\n    }\n    return asn1_time_to_tm(tm, s);\n}', "int asn1_time_to_tm(struct tm *tm, const ASN1_TIME *d)\n{\n    static const int min[9] = { 0, 0, 1, 1, 0, 0, 0, 0, 0 };\n    static const int max[9] = { 99, 99, 12, 31, 23, 59, 59, 12, 59 };\n    static const int mdays[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };\n    char *a;\n    int n, i, i2, l, o, min_l = 11, strict = 0, end = 6, btz = 5, md;\n    struct tm tmp;\n    if (d->type == V_ASN1_UTCTIME) {\n        if (d->flags & ASN1_STRING_FLAG_X509_TIME) {\n            min_l = 13;\n            strict = 1;\n        }\n    } else if (d->type == V_ASN1_GENERALIZEDTIME) {\n        end = 7;\n        btz = 6;\n        if (d->flags & ASN1_STRING_FLAG_X509_TIME) {\n            min_l = 15;\n            strict = 1;\n        } else {\n            min_l = 13;\n        }\n    } else {\n        return 0;\n    }\n    l = d->length;\n    a = (char *)d->data;\n    o = 0;\n    memset(&tmp, 0, sizeof(tmp));\n    if (l < min_l)\n        goto err;\n    for (i = 0; i < end; i++) {\n        if (!strict && (i == btz) && ((a[o] == 'Z') || (a[o] == '+') || (a[o] == '-'))) {\n            i++;\n            break;\n        }\n        if (!ossl_isdigit(a[o]))\n            goto err;\n        n = a[o] - '0';\n        if (++o == l)\n            goto err;\n        if (!ossl_isdigit(a[o]))\n            goto err;\n        n = (n * 10) + a[o] - '0';\n        if (++o == l)\n            goto err;\n        i2 = (d->type == V_ASN1_UTCTIME) ? i + 1 : i;\n        if ((n < min[i2]) || (n > max[i2]))\n            goto err;\n        switch (i2) {\n        case 0:\n            tmp.tm_year = n * 100 - 1900;\n            break;\n        case 1:\n            if (d->type == V_ASN1_UTCTIME)\n                tmp.tm_year = n < 50 ? n + 100 : n;\n            else\n                tmp.tm_year += n;\n            break;\n        case 2:\n            tmp.tm_mon = n - 1;\n            break;\n        case 3:\n            if (tmp.tm_mon == 1) {\n                md = mdays[1] + leap_year(tmp.tm_year + 1900);\n            } else {\n                md = mdays[tmp.tm_mon];\n            }\n            if (n > md)\n                goto err;\n            tmp.tm_mday = n;\n            determine_days(&tmp);\n            break;\n        case 4:\n            tmp.tm_hour = n;\n            break;\n        case 5:\n            tmp.tm_min = n;\n            break;\n        case 6:\n            tmp.tm_sec = n;\n            break;\n        }\n    }\n    if (d->type == V_ASN1_GENERALIZEDTIME && a[o] == '.') {\n        if (strict)\n            goto err;\n        if (++o == l)\n            goto err;\n        i = o;\n        while ((o < l) && ossl_isdigit(a[o]))\n            o++;\n        if (i == o)\n            goto err;\n        if (o == l)\n            goto err;\n    }\n    if (a[o] == 'Z') {\n        o++;\n    } else if (!strict && ((a[o] == '+') || (a[o] == '-'))) {\n        int offsign = a[o] == '-' ? 1 : -1;\n        int offset = 0;\n        o++;\n        if (o + 4 != l)\n            goto err;\n        for (i = end; i < end + 2; i++) {\n            if (!ossl_isdigit(a[o]))\n                goto err;\n            n = a[o] - '0';\n            o++;\n            if (!ossl_isdigit(a[o]))\n                goto err;\n            n = (n * 10) + a[o] - '0';\n            i2 = (d->type == V_ASN1_UTCTIME) ? i + 1 : i;\n            if ((n < min[i2]) || (n > max[i2]))\n                goto err;\n            if (tm != NULL) {\n                if (i == end)\n                    offset = n * 3600;\n                else if (i == end + 1)\n                    offset += n * 60;\n            }\n            o++;\n        }\n        if (offset && !OPENSSL_gmtime_adj(&tmp, 0, offset * offsign))\n            goto err;\n    } else {\n        goto err;\n    }\n    if (o == l) {\n        if (tm != NULL)\n            *tm = tmp;\n        return 1;\n    }\n err:\n    return 0;\n}"]