test/sslapitest.c:5831: error: BUFFER_OVERRUN_L1
  Offset: -1 Size: 1024 by call to `SSL_get_shared_ciphers`.
Showing all 6 steps of the trace


test/sslapitest.c:5798:1: Array declaration
5796.   };
5797.   
5798. > static int test_ssl_get_shared_ciphers(int tst)
5799.   {
5800.       SSL_CTX *cctx = NULL, *sctx = NULL;

test/sslapitest.c:5831:10: Call
5829.           goto end;
5830.   
5831.       if (!TEST_ptr(SSL_get_shared_ciphers(serverssl, buf, sizeof(buf)))
                 ^
5832.               || !TEST_int_eq(strcmp(buf, shared_ciphers_data[tst].shared), 0)) {
5833.           TEST_info("Shared ciphers are: %s\n", buf);

ssl/ssl_lib.c:2708:1: <Length trace>
2706.   }
2707.   
2708. > char *SSL_get_shared_ciphers(const SSL *s, char *buf, int size)
2709.   {
2710.       char *p;

ssl/ssl_lib.c:2708:1: Parameter `*buf`
  2706.   }
  2707.   
  2708. > char *SSL_get_shared_ciphers(const SSL *s, char *buf, int size)
  2709.   {
  2710.       char *p;

ssl/ssl_lib.c:2720:5: Assignment
  2718.           return NULL;
  2719.   
  2720.       p = buf;
              ^
  2721.       clntsk = s->peer_ciphers;
  2722.       srvrsk = SSL_get_ciphers(s);

ssl/ssl_lib.c:2748:5: Array access: Offset: -1 Size: 1024 by call to `SSL_get_shared_ciphers` 
  2746.           size -= n + 1;
  2747.       }
  2748.       p[-1] = '\0';
              ^
  2749.       return buf;
  2750.   }

char *SSL_get_shared_ciphers(const SSL *s, char *buf, int size)
{
    char *p;
    STACK_OF(SSL_CIPHER) *clntsk, *srvrsk;
    const SSL_CIPHER *c;
    int i;
    if (!s->server
            || s->peer_ciphers == NULL
            || size < 2)
        return NULL;
    p = buf;
    clntsk = s->peer_ciphers;
    srvrsk = SSL_get_ciphers(s);
    if (clntsk == NULL || srvrsk == NULL)
        return NULL;
    if (sk_SSL_CIPHER_num(clntsk) == 0 || sk_SSL_CIPHER_num(srvrsk) == 0)
        return NULL;
    for (i = 0; i < sk_SSL_CIPHER_num(clntsk); i++) {
        int n;
        c = sk_SSL_CIPHER_value(clntsk, i);
        if (sk_SSL_CIPHER_find(srvrsk, c) < 0)
            continue;
        n = strlen(c->name);
        if (n + 1 > size) {
            if (p != buf)
                --p;
            *p = '\0';
            return buf;
        }
        strcpy(p, c->name);
        p += n;
        *(p++) = ':';
        size -= n + 1;
    }
    p[-1] = '\0';
    return buf;
}
['static int test_ssl_get_shared_ciphers(int tst)\n{\n    SSL_CTX *cctx = NULL, *sctx = NULL;\n    SSL *clientssl = NULL, *serverssl = NULL;\n    int testresult = 0;\n    char buf[1024];\n    if (!TEST_true(create_ssl_ctx_pair(TLS_server_method(),\n                                       TLS_client_method(),\n                                       TLS1_VERSION,\n                                       shared_ciphers_data[tst].maxprot,\n                                       &sctx, &cctx, cert, privkey)))\n        goto end;\n    if (!TEST_true(SSL_CTX_set_cipher_list(cctx,\n                                        shared_ciphers_data[tst].clntciphers))\n            || (shared_ciphers_data[tst].clnttls13ciphers != NULL\n                && !TEST_true(SSL_CTX_set_ciphersuites(cctx,\n                                    shared_ciphers_data[tst].clnttls13ciphers)))\n            || !TEST_true(SSL_CTX_set_cipher_list(sctx,\n                                        shared_ciphers_data[tst].srvrciphers))\n            || (shared_ciphers_data[tst].srvrtls13ciphers != NULL\n                && !TEST_true(SSL_CTX_set_ciphersuites(sctx,\n                                    shared_ciphers_data[tst].srvrtls13ciphers))))\n        goto end;\n    if (!TEST_true(create_ssl_objects(sctx, cctx, &serverssl, &clientssl,\n                                             NULL, NULL))\n            || !TEST_true(create_ssl_connection(serverssl, clientssl,\n                                                SSL_ERROR_NONE)))\n        goto end;\n    if (!TEST_ptr(SSL_get_shared_ciphers(serverssl, buf, sizeof(buf)))\n            || !TEST_int_eq(strcmp(buf, shared_ciphers_data[tst].shared), 0)) {\n        TEST_info("Shared ciphers are: %s\\n", buf);\n        goto end;\n    }\n    testresult = 1;\n end:\n    SSL_free(serverssl);\n    SSL_free(clientssl);\n    SSL_CTX_free(sctx);\n    SSL_CTX_free(cctx);\n    return testresult;\n}', "char *SSL_get_shared_ciphers(const SSL *s, char *buf, int size)\n{\n    char *p;\n    STACK_OF(SSL_CIPHER) *clntsk, *srvrsk;\n    const SSL_CIPHER *c;\n    int i;\n    if (!s->server\n            || s->peer_ciphers == NULL\n            || size < 2)\n        return NULL;\n    p = buf;\n    clntsk = s->peer_ciphers;\n    srvrsk = SSL_get_ciphers(s);\n    if (clntsk == NULL || srvrsk == NULL)\n        return NULL;\n    if (sk_SSL_CIPHER_num(clntsk) == 0 || sk_SSL_CIPHER_num(srvrsk) == 0)\n        return NULL;\n    for (i = 0; i < sk_SSL_CIPHER_num(clntsk); i++) {\n        int n;\n        c = sk_SSL_CIPHER_value(clntsk, i);\n        if (sk_SSL_CIPHER_find(srvrsk, c) < 0)\n            continue;\n        n = strlen(c->name);\n        if (n + 1 > size) {\n            if (p != buf)\n                --p;\n            *p = '\\0';\n            return buf;\n        }\n        strcpy(p, c->name);\n        p += n;\n        *(p++) = ':';\n        size -= n + 1;\n    }\n    p[-1] = '\\0';\n    return buf;\n}"]