test/testutil/tests.c:447: error: BUFFER_OVERRUN_L3
  Offset: [1, +oo] Size: [0, +oo] by call to `ASN1_TIME_compare`.
Showing all 21 steps of the trace


test/testutil/tests.c:447:1: Call
445.   DEFINE_TIME_T_COMPARISON(gt, >)
446.   DEFINE_TIME_T_COMPARISON(ge, >=)
447. > DEFINE_TIME_T_COMPARISON(lt, <)
448.   DEFINE_TIME_T_COMPARISON(le, <=)

crypto/asn1/a_time.c:313:1: Parameter `*s->data`
  311.   }
  312.   
  313. > ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t t)
  314.   {
  315.       return ASN1_TIME_adj(s, t, 0, 0);

crypto/asn1/a_time.c:315:12: Call
  313.   ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t t)
  314.   {
  315.       return ASN1_TIME_adj(s, t, 0, 0);
                    ^
  316.   }
  317.   

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.   {

crypto/asn1/a_time.c:333:12: Call
    331.               return NULL;
    332.       }
    333.       return asn1_time_from_tm(s, ts, V_ASN1_UNDEF);
                      ^
    334.   }
    335.   

crypto/asn1/a_time.c:261:1: Parameter `*s->data`
      259.   }
      260.   
      261. > ASN1_TIME *asn1_time_from_tm(ASN1_TIME *s, struct tm *ts, int type)
      262.   {
      263.       char* p;

crypto/asn1/a_time.c:286:10: Call
      284.           return NULL;
      285.   
      286.       if (!ASN1_STRING_set(tmps, NULL, len))
                      ^
      287.           goto err;
      288.   

crypto/asn1/asn1_lib.c:271:1: Parameter `*str->data`
        269.   }
        270.   
        271. > int ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len)
        272.   {
        273.       unsigned char *c;

test/testutil/tests.c:447:1: Call
445.   DEFINE_TIME_T_COMPARISON(gt, >)
446.   DEFINE_TIME_T_COMPARISON(ge, >=)
447. > DEFINE_TIME_T_COMPARISON(lt, <)
448.   DEFINE_TIME_T_COMPARISON(le, <=)

crypto/asn1/a_time.c:542:1: Parameter `*a->data`
  540.   }
  541.   
  542. > int ASN1_TIME_compare(const ASN1_TIME *a, const ASN1_TIME *b)
  543.   {
  544.       int day, sec;

crypto/asn1/a_time.c:546:10: Call
  544.       int day, sec;
  545.   
  546.       if (!ASN1_TIME_diff(&day, &sec, b, a))
                  ^
  547.           return -2;
  548.       if (day > 0 || sec > 0)

crypto/asn1/a_time.c:448:1: Parameter `*to->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:455:10: Call
    453.       if (!ASN1_TIME_to_tm(from, &tm_from))
    454.           return 0;
    455.       if (!ASN1_TIME_to_tm(to, &tm_to))
                    ^
    456.           return 0;
    457.       return OPENSSL_gmtime_diff(pday, psec, &tm_from, &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 `ASN1_TIME_compare` 
        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;
}
['DEFINE_TIME_T_COMPARISON(lt, <)', 'ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t t)\n{\n    return ASN1_TIME_adj(s, t, 0, 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}', 'ASN1_TIME *asn1_time_from_tm(ASN1_TIME *s, struct tm *ts, int type)\n{\n    char* p;\n    ASN1_TIME *tmps = NULL;\n    const size_t len = 20;\n    if (type == V_ASN1_UNDEF) {\n        if (is_utc(ts->tm_year))\n            type = V_ASN1_UTCTIME;\n        else\n            type = V_ASN1_GENERALIZEDTIME;\n    } else if (type == V_ASN1_UTCTIME) {\n        if (!is_utc(ts->tm_year))\n            goto err;\n    } else if (type != V_ASN1_GENERALIZEDTIME) {\n        goto err;\n    }\n    if (s == NULL)\n        tmps = ASN1_STRING_new();\n    else\n        tmps = s;\n    if (tmps == NULL)\n        return NULL;\n    if (!ASN1_STRING_set(tmps, NULL, len))\n        goto err;\n    tmps->type = type;\n    p = (char*)tmps->data;\n    if (type == V_ASN1_GENERALIZEDTIME)\n        tmps->length = BIO_snprintf(p, len, "%04d%02d%02d%02d%02d%02dZ",\n                                    ts->tm_year + 1900, ts->tm_mon + 1,\n                                    ts->tm_mday, ts->tm_hour, ts->tm_min,\n                                    ts->tm_sec);\n    else\n        tmps->length = BIO_snprintf(p, len, "%02d%02d%02d%02d%02d%02dZ",\n                                    ts->tm_year % 100, ts->tm_mon + 1,\n                                    ts->tm_mday, ts->tm_hour, ts->tm_min,\n                                    ts->tm_sec);\n#ifdef CHARSET_EBCDIC_not\n    ebcdic2ascii(tmps->data, tmps->data, tmps->length);\n#endif\n    return tmps;\n err:\n    if (tmps != s)\n        ASN1_STRING_free(tmps);\n    return NULL;\n}', "int ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len)\n{\n    unsigned char *c;\n    const char *data = _data;\n    if (len < 0) {\n        if (data == NULL)\n            return 0;\n        else\n            len = strlen(data);\n    }\n    if ((str->length <= len) || (str->data == NULL)) {\n        c = str->data;\n        str->data = OPENSSL_realloc(c, len + 1);\n        if (str->data == NULL) {\n            ASN1err(ASN1_F_ASN1_STRING_SET, ERR_R_MALLOC_FAILURE);\n            str->data = c;\n            return 0;\n        }\n    }\n    str->length = len;\n    if (data != NULL) {\n        memcpy(str->data, data, len);\n        str->data[len] = '\\0';\n    }\n    return 1;\n}", 'int ASN1_TIME_compare(const ASN1_TIME *a, const ASN1_TIME *b)\n{\n    int day, sec;\n    if (!ASN1_TIME_diff(&day, &sec, b, a))\n        return -2;\n    if (day > 0 || sec > 0)\n        return 1;\n    if (day < 0 || sec < 0)\n        return -1;\n    return 0;\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}"]