apps/s_server.c:2521: error: BUFFER_OVERRUN_L3
  Offset: [199, 8191] Size: [1, 2147483644] by call to `X509_NAME_oneline`.
Showing all 6 steps of the trace


apps/s_server.c:2521:9: Call
2519.           BIO_printf(bio_s_out, "Client certificate\n");
2520.           PEM_write_bio_X509(bio_s_out, peer);
2521.           X509_NAME_oneline(X509_get_subject_name(peer), buf, sizeof buf);
                ^
2522.           BIO_printf(bio_s_out, "subject=%s\n", buf);
2523.           X509_NAME_oneline(X509_get_issuer_name(peer), buf, sizeof buf);

crypto/x509/x509_obj.c:66:1: <Offset trace>
64.   #include "internal/x509_int.h"
65.   
66. > char *X509_NAME_oneline(X509_NAME *a, char *buf, int len)
67.   {
68.       X509_NAME_ENTRY *ne;

crypto/x509/x509_obj.c:66:1: Parameter `len`
  64.   #include "internal/x509_int.h"
  65.   
  66. > char *X509_NAME_oneline(X509_NAME *a, char *buf, int len)
  67.   {
  68.       X509_NAME_ENTRY *ne;

crypto/x509/x509_obj.c:66:1: <Length trace>
64.   #include "internal/x509_int.h"
65.   
66. > char *X509_NAME_oneline(X509_NAME *a, char *buf, int len)
67.   {
68.       X509_NAME_ENTRY *ne;

crypto/x509/x509_obj.c:66:1: Parameter `*buf`
  64.   #include "internal/x509_int.h"
  65.   
  66. > char *X509_NAME_oneline(X509_NAME *a, char *buf, int len)
  67.   {
  68.       X509_NAME_ENTRY *ne;

crypto/x509/x509_obj.c:96:9: Array access: Offset: [199, 8191] Size: [1, 2147483644] by call to `X509_NAME_oneline` 
  94.           }
  95.           strncpy(buf, "NO X509_NAME", len);
  96.           buf[len - 1] = '\0';
                ^
  97.           return buf;
  98.       }

char *X509_NAME_oneline(X509_NAME *a, char *buf, int len)
{
    X509_NAME_ENTRY *ne;
    int i;
    int n, lold, l, l1, l2, num, j, type;
    const char *s;
    char *p;
    unsigned char *q;
    BUF_MEM *b = NULL;
    static const char hex[17] = "0123456789ABCDEF";
    int gs_doit[4];
    char tmp_buf[80];
#ifdef CHARSET_EBCDIC
    char ebcdic_buf[1024];
#endif
    if (buf == NULL) {
        if ((b = BUF_MEM_new()) == NULL)
            goto err;
        if (!BUF_MEM_grow(b, 200))
            goto err;
        b->data[0] = '\0';
        len = 200;
    }
    if (a == NULL) {
        if (b) {
            buf = b->data;
            OPENSSL_free(b);
        }
        strncpy(buf, "NO X509_NAME", len);
        buf[len - 1] = '\0';
        return buf;
    }
    len--;
    l = 0;
    for (i = 0; i < sk_X509_NAME_ENTRY_num(a->entries); i++) {
        ne = sk_X509_NAME_ENTRY_value(a->entries, i);
        n = OBJ_obj2nid(ne->object);
        if ((n == NID_undef) || ((s = OBJ_nid2sn(n)) == NULL)) {
            i2t_ASN1_OBJECT(tmp_buf, sizeof(tmp_buf), ne->object);
            s = tmp_buf;
        }
        l1 = strlen(s);
        type = ne->value->type;
        num = ne->value->length;
        q = ne->value->data;
#ifdef CHARSET_EBCDIC
        if (type == V_ASN1_GENERALSTRING ||
            type == V_ASN1_VISIBLESTRING ||
            type == V_ASN1_PRINTABLESTRING ||
            type == V_ASN1_TELETEXSTRING ||
            type == V_ASN1_VISIBLESTRING || type == V_ASN1_IA5STRING) {
            ascii2ebcdic(ebcdic_buf, q, (num > sizeof ebcdic_buf)
                         ? sizeof ebcdic_buf : num);
            q = ebcdic_buf;
        }
#endif
        if ((type == V_ASN1_GENERALSTRING) && ((num % 4) == 0)) {
            gs_doit[0] = gs_doit[1] = gs_doit[2] = gs_doit[3] = 0;
            for (j = 0; j < num; j++)
                if (q[j] != 0)
                    gs_doit[j & 3] = 1;
            if (gs_doit[0] | gs_doit[1] | gs_doit[2])
                gs_doit[0] = gs_doit[1] = gs_doit[2] = gs_doit[3] = 1;
            else {
                gs_doit[0] = gs_doit[1] = gs_doit[2] = 0;
                gs_doit[3] = 1;
            }
        } else
            gs_doit[0] = gs_doit[1] = gs_doit[2] = gs_doit[3] = 1;
        for (l2 = j = 0; j < num; j++) {
            if (!gs_doit[j & 3])
                continue;
            l2++;
#ifndef CHARSET_EBCDIC
            if ((q[j] < ' ') || (q[j] > '~'))
                l2 += 3;
#else
            if ((os_toascii[q[j]] < os_toascii[' ']) ||
                (os_toascii[q[j]] > os_toascii['~']))
                l2 += 3;
#endif
        }
        lold = l;
        l += 1 + l1 + 1 + l2;
        if (b != NULL) {
            if (!BUF_MEM_grow(b, l + 1))
                goto err;
            p = &(b->data[lold]);
        } else if (l > len) {
            break;
        } else
            p = &(buf[lold]);
        *(p++) = '/';
        memcpy(p, s, (unsigned int)l1);
        p += l1;
        *(p++) = '=';
#ifndef CHARSET_EBCDIC
        q = ne->value->data;
#endif
        for (j = 0; j < num; j++) {
            if (!gs_doit[j & 3])
                continue;
#ifndef CHARSET_EBCDIC
            n = q[j];
            if ((n < ' ') || (n > '~')) {
                *(p++) = '\\';
                *(p++) = 'x';
                *(p++) = hex[(n >> 4) & 0x0f];
                *(p++) = hex[n & 0x0f];
            } else
                *(p++) = n;
#else
            n = os_toascii[q[j]];
            if ((n < os_toascii[' ']) || (n > os_toascii['~'])) {
                *(p++) = '\\';
                *(p++) = 'x';
                *(p++) = hex[(n >> 4) & 0x0f];
                *(p++) = hex[n & 0x0f];
            } else
                *(p++) = q[j];
#endif
        }
        *p = '\0';
    }
    if (b != NULL) {
        p = b->data;
        OPENSSL_free(b);
    } else
        p = buf;
    if (i == 0)
        *p = '\0';
    return (p);
 err:
    X509err(X509_F_X509_NAME_ONELINE, ERR_R_MALLOC_FAILURE);
    BUF_MEM_free(b);
    return (NULL);
}
['static int init_ssl_connection(SSL *con)\n{\n    int i;\n    const char *str;\n    X509 *peer;\n    long verify_err;\n    char buf[BUFSIZ];\n#if !defined(OPENSSL_NO_NEXTPROTONEG)\n    const unsigned char *next_proto_neg;\n    unsigned next_proto_neg_len;\n#endif\n    unsigned char *exportedkeymat;\n#ifndef OPENSSL_NO_DTLS\n    struct sockaddr_storage client;\n#endif\n#ifndef OPENSSL_NO_DTLS\n    if(dtlslisten) {\n        i = DTLSv1_listen(con, &client);\n        if (i > 0) {\n            BIO *wbio;\n            int fd = -1;\n            wbio = SSL_get_wbio(con);\n            if(wbio) {\n                BIO_get_fd(wbio, &fd);\n            }\n            if(!wbio || connect(fd, (struct sockaddr *)&client,\n                                sizeof(struct sockaddr_storage))) {\n                BIO_printf(bio_err, "ERROR - unable to connect\\n");\n                return 0;\n            }\n            dtlslisten = 0;\n            i = SSL_accept(con);\n        }\n    } else\n#endif\n    do {\n        i = SSL_accept(con);\n#ifdef CERT_CB_TEST_RETRY\n        {\n            while (i <= 0 && SSL_get_error(con, i) == SSL_ERROR_WANT_X509_LOOKUP\n                    && SSL_get_state(con) == TLS_ST_SR_CLNT_HELLO) {\n                BIO_printf(bio_err,\n                       "LOOKUP from certificate callback during accept\\n");\n                i = SSL_accept(con);\n            }\n        }\n#endif\n#ifndef OPENSSL_NO_SRP\n        while (i <= 0 && SSL_get_error(con, i) == SSL_ERROR_WANT_X509_LOOKUP) {\n            BIO_printf(bio_s_out, "LOOKUP during accept %s\\n",\n                       srp_callback_parm.login);\n            srp_callback_parm.user =\n                SRP_VBASE_get_by_user(srp_callback_parm.vb,\n                                      srp_callback_parm.login);\n            if (srp_callback_parm.user)\n                BIO_printf(bio_s_out, "LOOKUP done %s\\n",\n                           srp_callback_parm.user->info);\n            else\n                BIO_printf(bio_s_out, "LOOKUP not successful\\n");\n            i = SSL_accept(con);\n        }\n#endif\n    } while (i < 0 && SSL_waiting_for_async(con));\n    if (i <= 0) {\n        if ((dtlslisten && i == 0)\n                || (!dtlslisten && BIO_sock_should_retry(i))) {\n            BIO_printf(bio_s_out, "DELAY\\n");\n            return (1);\n        }\n        BIO_printf(bio_err, "ERROR\\n");\n        verify_err = SSL_get_verify_result(con);\n        if (verify_err != X509_V_OK) {\n            BIO_printf(bio_err, "verify error:%s\\n",\n                       X509_verify_cert_error_string(verify_err));\n        }\n        ERR_print_errors(bio_err);\n        return (0);\n    }\n    if (s_brief)\n        print_ssl_summary(con);\n    PEM_write_bio_SSL_SESSION(bio_s_out, SSL_get_session(con));\n    peer = SSL_get_peer_certificate(con);\n    if (peer != NULL) {\n        BIO_printf(bio_s_out, "Client certificate\\n");\n        PEM_write_bio_X509(bio_s_out, peer);\n        X509_NAME_oneline(X509_get_subject_name(peer), buf, sizeof buf);\n        BIO_printf(bio_s_out, "subject=%s\\n", buf);\n        X509_NAME_oneline(X509_get_issuer_name(peer), buf, sizeof buf);\n        BIO_printf(bio_s_out, "issuer=%s\\n", buf);\n        X509_free(peer);\n    }\n    if (SSL_get_shared_ciphers(con, buf, sizeof buf) != NULL)\n        BIO_printf(bio_s_out, "Shared ciphers:%s\\n", buf);\n    str = SSL_CIPHER_get_name(SSL_get_current_cipher(con));\n    ssl_print_sigalgs(bio_s_out, con);\n#ifndef OPENSSL_NO_EC\n    ssl_print_point_formats(bio_s_out, con);\n    ssl_print_curves(bio_s_out, con, 0);\n#endif\n    BIO_printf(bio_s_out, "CIPHER is %s\\n", (str != NULL) ? str : "(NONE)");\n#if !defined(OPENSSL_NO_NEXTPROTONEG)\n    SSL_get0_next_proto_negotiated(con, &next_proto_neg, &next_proto_neg_len);\n    if (next_proto_neg) {\n        BIO_printf(bio_s_out, "NEXTPROTO is ");\n        BIO_write(bio_s_out, next_proto_neg, next_proto_neg_len);\n        BIO_printf(bio_s_out, "\\n");\n    }\n#endif\n#ifndef OPENSSL_NO_SRTP\n    {\n        SRTP_PROTECTION_PROFILE *srtp_profile\n            = SSL_get_selected_srtp_profile(con);\n        if (srtp_profile)\n            BIO_printf(bio_s_out, "SRTP Extension negotiated, profile=%s\\n",\n                       srtp_profile->name);\n    }\n#endif\n    if (SSL_cache_hit(con))\n        BIO_printf(bio_s_out, "Reused session-id\\n");\n    BIO_printf(bio_s_out, "Secure Renegotiation IS%s supported\\n",\n               SSL_get_secure_renegotiation_support(con) ? "" : " NOT");\n    if (keymatexportlabel != NULL) {\n        BIO_printf(bio_s_out, "Keying material exporter:\\n");\n        BIO_printf(bio_s_out, "    Label: \'%s\'\\n", keymatexportlabel);\n        BIO_printf(bio_s_out, "    Length: %i bytes\\n", keymatexportlen);\n        exportedkeymat = app_malloc(keymatexportlen, "export key");\n        if (!SSL_export_keying_material(con, exportedkeymat,\n                                        keymatexportlen,\n                                        keymatexportlabel,\n                                        strlen(keymatexportlabel),\n                                        NULL, 0, 0)) {\n            BIO_printf(bio_s_out, "    Error\\n");\n        } else {\n            BIO_printf(bio_s_out, "    Keying material: ");\n            for (i = 0; i < keymatexportlen; i++)\n                BIO_printf(bio_s_out, "%02X", exportedkeymat[i]);\n            BIO_printf(bio_s_out, "\\n");\n        }\n        OPENSSL_free(exportedkeymat);\n    }\n    return (1);\n}', 'char *X509_NAME_oneline(X509_NAME *a, char *buf, int len)\n{\n    X509_NAME_ENTRY *ne;\n    int i;\n    int n, lold, l, l1, l2, num, j, type;\n    const char *s;\n    char *p;\n    unsigned char *q;\n    BUF_MEM *b = NULL;\n    static const char hex[17] = "0123456789ABCDEF";\n    int gs_doit[4];\n    char tmp_buf[80];\n#ifdef CHARSET_EBCDIC\n    char ebcdic_buf[1024];\n#endif\n    if (buf == NULL) {\n        if ((b = BUF_MEM_new()) == NULL)\n            goto err;\n        if (!BUF_MEM_grow(b, 200))\n            goto err;\n        b->data[0] = \'\\0\';\n        len = 200;\n    }\n    if (a == NULL) {\n        if (b) {\n            buf = b->data;\n            OPENSSL_free(b);\n        }\n        strncpy(buf, "NO X509_NAME", len);\n        buf[len - 1] = \'\\0\';\n        return buf;\n    }\n    len--;\n    l = 0;\n    for (i = 0; i < sk_X509_NAME_ENTRY_num(a->entries); i++) {\n        ne = sk_X509_NAME_ENTRY_value(a->entries, i);\n        n = OBJ_obj2nid(ne->object);\n        if ((n == NID_undef) || ((s = OBJ_nid2sn(n)) == NULL)) {\n            i2t_ASN1_OBJECT(tmp_buf, sizeof(tmp_buf), ne->object);\n            s = tmp_buf;\n        }\n        l1 = strlen(s);\n        type = ne->value->type;\n        num = ne->value->length;\n        q = ne->value->data;\n#ifdef CHARSET_EBCDIC\n        if (type == V_ASN1_GENERALSTRING ||\n            type == V_ASN1_VISIBLESTRING ||\n            type == V_ASN1_PRINTABLESTRING ||\n            type == V_ASN1_TELETEXSTRING ||\n            type == V_ASN1_VISIBLESTRING || type == V_ASN1_IA5STRING) {\n            ascii2ebcdic(ebcdic_buf, q, (num > sizeof ebcdic_buf)\n                         ? sizeof ebcdic_buf : num);\n            q = ebcdic_buf;\n        }\n#endif\n        if ((type == V_ASN1_GENERALSTRING) && ((num % 4) == 0)) {\n            gs_doit[0] = gs_doit[1] = gs_doit[2] = gs_doit[3] = 0;\n            for (j = 0; j < num; j++)\n                if (q[j] != 0)\n                    gs_doit[j & 3] = 1;\n            if (gs_doit[0] | gs_doit[1] | gs_doit[2])\n                gs_doit[0] = gs_doit[1] = gs_doit[2] = gs_doit[3] = 1;\n            else {\n                gs_doit[0] = gs_doit[1] = gs_doit[2] = 0;\n                gs_doit[3] = 1;\n            }\n        } else\n            gs_doit[0] = gs_doit[1] = gs_doit[2] = gs_doit[3] = 1;\n        for (l2 = j = 0; j < num; j++) {\n            if (!gs_doit[j & 3])\n                continue;\n            l2++;\n#ifndef CHARSET_EBCDIC\n            if ((q[j] < \' \') || (q[j] > \'~\'))\n                l2 += 3;\n#else\n            if ((os_toascii[q[j]] < os_toascii[\' \']) ||\n                (os_toascii[q[j]] > os_toascii[\'~\']))\n                l2 += 3;\n#endif\n        }\n        lold = l;\n        l += 1 + l1 + 1 + l2;\n        if (b != NULL) {\n            if (!BUF_MEM_grow(b, l + 1))\n                goto err;\n            p = &(b->data[lold]);\n        } else if (l > len) {\n            break;\n        } else\n            p = &(buf[lold]);\n        *(p++) = \'/\';\n        memcpy(p, s, (unsigned int)l1);\n        p += l1;\n        *(p++) = \'=\';\n#ifndef CHARSET_EBCDIC\n        q = ne->value->data;\n#endif\n        for (j = 0; j < num; j++) {\n            if (!gs_doit[j & 3])\n                continue;\n#ifndef CHARSET_EBCDIC\n            n = q[j];\n            if ((n < \' \') || (n > \'~\')) {\n                *(p++) = \'\\\\\';\n                *(p++) = \'x\';\n                *(p++) = hex[(n >> 4) & 0x0f];\n                *(p++) = hex[n & 0x0f];\n            } else\n                *(p++) = n;\n#else\n            n = os_toascii[q[j]];\n            if ((n < os_toascii[\' \']) || (n > os_toascii[\'~\'])) {\n                *(p++) = \'\\\\\';\n                *(p++) = \'x\';\n                *(p++) = hex[(n >> 4) & 0x0f];\n                *(p++) = hex[n & 0x0f];\n            } else\n                *(p++) = q[j];\n#endif\n        }\n        *p = \'\\0\';\n    }\n    if (b != NULL) {\n        p = b->data;\n        OPENSSL_free(b);\n    } else\n        p = buf;\n    if (i == 0)\n        *p = \'\\0\';\n    return (p);\n err:\n    X509err(X509_F_X509_NAME_ONELINE, ERR_R_MALLOC_FAILURE);\n    BUF_MEM_free(b);\n    return (NULL);\n}']