test/asn1_time_test.c:164: error: BUFFER_OVERRUN_L3
  Offset: [1, +oo] Size: [0, +oo] by call to `ASN1_TIME_cmp_time_t`.
Showing all 15 steps of the trace


test/asn1_time_test.c:158:13: Call
156.       }
157.   
158.       ptime = ASN1_TIME_set(NULL, td->t);
                   ^
159.       if (!TEST_ptr(ptime)) {
160.           TEST_info("ASN1_TIME_set(%ld) failed", (long)td->t);

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

test/asn1_time_test.c:164:14: Call
162.       } else {
163.           int local_error = 0;
164.           if (!TEST_int_eq(ASN1_TIME_cmp_time_t(ptime, td->t), 0)) {
                    ^
165.               TEST_info("ASN1_TIME_set(%ld) compare failed (%s->%s)",
166.                       (long)td->t, td->data, ptime->data);

crypto/asn1/a_time.c:511:1: Parameter `*s->data`
  509.   }
  510.   
  511. > int ASN1_TIME_cmp_time_t(const ASN1_TIME *s, time_t t)
  512.   {
  513.       struct tm stm, ttm;

crypto/asn1/a_time.c:516:10: Call
  514.       int day, sec;
  515.   
  516.       if (!ASN1_TIME_to_tm(s, &stm))
                  ^
  517.           return -2;
  518.   

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_cmp_time_t` 
      132.               goto err;
      133.   
      134.           if (!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 (!isdigit(a[o]))
            goto err;
        n = a[o] - '0';
        if (++o == l)
            goto err;
        if (!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) && 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 (!isdigit(a[o]))
                goto err;
            n = a[o] - '0';
            o++;
            if (!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_table(struct testdata *tbl, int idx)\n{\n    int error = 0;\n    ASN1_TIME atime;\n    ASN1_TIME *ptime;\n    struct testdata *td = &tbl[idx];\n    int day, sec;\n    atime.data = (unsigned char*)td->data;\n    atime.length = strlen((char*)atime.data);\n    atime.type = td->type;\n    atime.flags = 0;\n    if (!TEST_int_eq(ASN1_TIME_check(&atime), td->check_result)) {\n        TEST_info("ASN1_TIME_check(%s) unexpected result", atime.data);\n        error = 1;\n    }\n    if (td->check_result == 0)\n        return 1;\n    if (!TEST_int_eq(ASN1_TIME_cmp_time_t(&atime, td->t), 0)) {\n        TEST_info("ASN1_TIME_cmp_time_t(%s vs %ld) compare failed", atime.data, (long)td->t);\n        error = 1;\n    }\n    if (!TEST_true(ASN1_TIME_diff(&day, &sec, &atime, &atime))) {\n        TEST_info("ASN1_TIME_diff(%s) to self failed", atime.data);\n        error = 1;\n    }\n    if (!TEST_int_eq(day, 0) || !TEST_int_eq(sec, 0)) {\n        TEST_info("ASN1_TIME_diff(%s) to self not equal", atime.data);\n        error = 1;\n    }\n    if (!TEST_true(ASN1_TIME_diff(&day, &sec, &gtime, &atime))) {\n        TEST_info("ASN1_TIME_diff(%s) to baseline failed", atime.data);\n        error = 1;\n    } else if (!((td->cmp_result == 0 && TEST_true((day == 0 && sec == 0))) ||\n                 (td->cmp_result == -1 && TEST_true((day < 0 || sec < 0))) ||\n                 (td->cmp_result == 1 && TEST_true((day > 0 || sec > 0))))) {\n        TEST_info("ASN1_TIME_diff(%s) to baseline bad comparison", atime.data);\n        error = 1;\n    }\n    if (!TEST_int_eq(ASN1_TIME_cmp_time_t(&atime, gtime_t), td->cmp_result)) {\n        TEST_info("ASN1_TIME_cmp_time_t(%s) to baseline bad comparison", atime.data);\n        error = 1;\n    }\n    ptime = ASN1_TIME_set(NULL, td->t);\n    if (!TEST_ptr(ptime)) {\n        TEST_info("ASN1_TIME_set(%ld) failed", (long)td->t);\n        error = 1;\n    } else {\n        int local_error = 0;\n        if (!TEST_int_eq(ASN1_TIME_cmp_time_t(ptime, td->t), 0)) {\n            TEST_info("ASN1_TIME_set(%ld) compare failed (%s->%s)",\n                    (long)td->t, td->data, ptime->data);\n            local_error = error = 1;\n        }\n        if (!TEST_int_eq(ptime->type, td->expected_type)) {\n            TEST_info("ASN1_TIME_set(%ld) unexpected type", (long)td->t);\n            local_error = error = 1;\n        }\n        if (local_error)\n            TEST_info("ASN1_TIME_set() = %*s", ptime->length, ptime->data);\n        ASN1_TIME_free(ptime);\n    }\n    ptime = ASN1_TIME_new();\n    if (!TEST_ptr(ptime)) {\n        TEST_info("ASN1_TIME_new() failed");\n        error = 1;\n    } else {\n        int local_error = 0;\n        if (!TEST_int_eq(ASN1_TIME_set_string(ptime, td->data), td->check_result)) {\n            TEST_info("ASN1_TIME_set_string_gmt(%s) failed", td->data);\n            local_error = error = 1;\n        }\n        if (!TEST_int_eq(ASN1_TIME_normalize(ptime), td->check_result)) {\n            TEST_info("ASN1_TIME_normalize(%s) failed", td->data);\n            local_error = error = 1;\n        }\n        if (!TEST_int_eq(ptime->type, td->expected_type)) {\n            TEST_info("ASN1_TIME_set_string_gmt(%s) unexpected type", td->data);\n            local_error = error = 1;\n        }\n        day = sec = 0;\n        if (!TEST_true(ASN1_TIME_diff(&day, &sec, ptime, &atime)) || !TEST_int_eq(day, 0) || !TEST_int_eq(sec, 0)) {\n            TEST_info("ASN1_TIME_diff(day=%d, sec=%d, %s) after ASN1_TIME_set_string_gmt() failed", day, sec, td->data);\n            local_error = error = 1;\n        }\n        if (!TEST_int_eq(ASN1_TIME_cmp_time_t(ptime, gtime_t), td->cmp_result)) {\n            TEST_info("ASN1_TIME_cmp_time_t(%s) after ASN1_TIME_set_string_gnt() to baseline bad comparison", td->data);\n            local_error = error = 1;\n        }\n        if (local_error)\n            TEST_info("ASN1_TIME_set_string_gmt() = %*s", ptime->length, ptime->data);\n        ASN1_TIME_free(ptime);\n    }\n    ptime = ASN1_TIME_new();\n    if (!TEST_ptr(ptime)) {\n        TEST_info("ASN1_TIME_new() failed");\n        error = 1;\n    } else {\n        int local_error = 0;\n        if (!TEST_int_eq(ASN1_TIME_set_string(ptime, td->data), td->check_result)) {\n            TEST_info("ASN1_TIME_set_string(%s) failed", td->data);\n            local_error = error = 1;\n        }\n        day = sec = 0;\n        if (!TEST_true(ASN1_TIME_diff(&day, &sec, ptime, &atime)) || !TEST_int_eq(day, 0) || !TEST_int_eq(sec, 0)) {\n            TEST_info("ASN1_TIME_diff(day=%d, sec=%d, %s) after ASN1_TIME_set_string() failed", day, sec, td->data);\n            local_error = error = 1;\n        }\n        if (!TEST_int_eq(ASN1_TIME_cmp_time_t(ptime, gtime_t), td->cmp_result)) {\n            TEST_info("ASN1_TIME_cmp_time_t(%s) after ASN1_TIME_set_string() to baseline bad comparison", td->data);\n            local_error = error = 1;\n        }\n        if (local_error)\n            TEST_info("ASN1_TIME_set_string() = %*s", ptime->length, ptime->data);\n        ASN1_TIME_free(ptime);\n    }\n    if (td->type == V_ASN1_UTCTIME) {\n        ptime = ASN1_TIME_to_generalizedtime(&atime, NULL);\n        if (td->convert_result == 1 && !TEST_ptr(ptime)) {\n            TEST_info("ASN1_TIME_to_generalizedtime(%s) failed", atime.data);\n            error = 1;\n        } else if (td->convert_result == 0 && !TEST_ptr_null(ptime)) {\n            TEST_info("ASN1_TIME_to_generalizedtime(%s) should have failed", atime.data);\n            error = 1;\n        }\n        if (ptime != NULL && !TEST_int_eq(ASN1_TIME_cmp_time_t(ptime, td->t), 0)) {\n            TEST_info("ASN1_TIME_to_generalizedtime(%s->%s) bad result", atime.data, ptime->data);\n            error = 1;\n        }\n        ASN1_TIME_free(ptime);\n    }\n    if (error)\n        TEST_error("atime=%s", atime.data);\n    return !error;\n}', '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}', 'int ASN1_TIME_cmp_time_t(const ASN1_TIME *s, time_t t)\n{\n    struct tm stm, ttm;\n    int day, sec;\n    if (!ASN1_TIME_to_tm(s, &stm))\n        return -2;\n    if (!OPENSSL_gmtime(&t, &ttm))\n        return -2;\n    if (!OPENSSL_gmtime_diff(&day, &sec, &ttm, &stm))\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_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 (!isdigit(a[o]))\n            goto err;\n        n = a[o] - '0';\n        if (++o == l)\n            goto err;\n        if (!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) && 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 (!isdigit(a[o]))\n                goto err;\n            n = a[o] - '0';\n            o++;\n            if (!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}"]