ssl/t1_enc.c:786: error: BUFFER_OVERRUN_S2
  Offset: `llen` + 65 Size: [`llen` + 64, `llen` + `contextlen` + 66].
Showing all 13 steps of the trace


ssl/t1_enc.c:748:1: <Offset trace>
746.   }
747.   
748. > int tls1_export_keying_material(SSL *s, unsigned char *out, size_t olen,
749.                                   const char *label, size_t llen,
750.                                   const unsigned char *context,

ssl/t1_enc.c:748:1: Parameter `llen`
746.   }
747.   
748. > int tls1_export_keying_material(SSL *s, unsigned char *out, size_t olen,
749.                                   const char *label, size_t llen,
750.                                   const unsigned char *context,

ssl/t1_enc.c:777:5: Assignment
775.       currentvalpos = 0;
776.       memcpy(val + currentvalpos, (unsigned char *)label, llen);
777.       currentvalpos += llen;
           ^
778.       memcpy(val + currentvalpos, s->s3->client_random, SSL3_RANDOM_SIZE);
779.       currentvalpos += SSL3_RANDOM_SIZE;

ssl/t1_enc.c:779:5: Assignment
777.       currentvalpos += llen;
778.       memcpy(val + currentvalpos, s->s3->client_random, SSL3_RANDOM_SIZE);
779.       currentvalpos += SSL3_RANDOM_SIZE;
           ^
780.       memcpy(val + currentvalpos, s->s3->server_random, SSL3_RANDOM_SIZE);
781.       currentvalpos += SSL3_RANDOM_SIZE;

ssl/t1_enc.c:781:5: Assignment
779.       currentvalpos += SSL3_RANDOM_SIZE;
780.       memcpy(val + currentvalpos, s->s3->server_random, SSL3_RANDOM_SIZE);
781.       currentvalpos += SSL3_RANDOM_SIZE;
           ^
782.   
783.       if (use_context) {

ssl/t1_enc.c:785:9: Assignment
783.       if (use_context) {
784.           val[currentvalpos] = (contextlen >> 8) & 0xff;
785.           currentvalpos++;
               ^
786.           val[currentvalpos] = contextlen & 0xff;
787.           currentvalpos++;

ssl/t1_enc.c:748:1: <Length trace>
746.   }
747.   
748. > int tls1_export_keying_material(SSL *s, unsigned char *out, size_t olen,
749.                                   const char *label, size_t llen,
750.                                   const unsigned char *context,

ssl/t1_enc.c:748:1: Parameter `llen`
746.   }
747.   
748. > int tls1_export_keying_material(SSL *s, unsigned char *out, size_t olen,
749.                                   const char *label, size_t llen,
750.                                   const unsigned char *context,

ssl/t1_enc.c:767:5: Assignment
765.        * concatenation of values does not create a prohibited label.
766.        */
767.       vallen = llen + SSL3_RANDOM_SIZE * 2;
           ^
768.       if (use_context) {
769.           vallen += 2 + contextlen;

ssl/t1_enc.c:772:11: Call
770.       }
771.   
772.       val = OPENSSL_malloc(vallen);
                 ^
773.       if (val == NULL)
774.           goto err2;

crypto/mem.c:125:9: Assignment
  123.   
  124.       if (num <= 0)
  125.           return NULL;
                 ^
  126.   
  127.       allow_customize = 0;

ssl/t1_enc.c:772:5: Assignment
770.       }
771.   
772.       val = OPENSSL_malloc(vallen);
           ^
773.       if (val == NULL)
774.           goto err2;

ssl/t1_enc.c:786:9: Array access: Offset: llen + 65 Size: [llen + 64, llen + contextlen + 66]
784.           val[currentvalpos] = (contextlen >> 8) & 0xff;
785.           currentvalpos++;
786.           val[currentvalpos] = contextlen & 0xff;
               ^
787.           currentvalpos++;
788.           if ((contextlen > 0) || (context != NULL)) {

int tls1_export_keying_material(SSL *s, unsigned char *out, size_t olen,
                                const char *label, size_t llen,
                                const unsigned char *context,
                                size_t contextlen, int use_context)
{
    unsigned char *buff;
    unsigned char *val = NULL;
    size_t vallen = 0, currentvalpos;
    int rv;
    buff = OPENSSL_malloc(olen);
    if (buff == NULL)
        goto err2;
    vallen = llen + SSL3_RANDOM_SIZE * 2;
    if (use_context) {
        vallen += 2 + contextlen;
    }
    val = OPENSSL_malloc(vallen);
    if (val == NULL)
        goto err2;
    currentvalpos = 0;
    memcpy(val + currentvalpos, (unsigned char *)label, llen);
    currentvalpos += llen;
    memcpy(val + currentvalpos, s->s3->client_random, SSL3_RANDOM_SIZE);
    currentvalpos += SSL3_RANDOM_SIZE;
    memcpy(val + currentvalpos, s->s3->server_random, SSL3_RANDOM_SIZE);
    currentvalpos += SSL3_RANDOM_SIZE;
    if (use_context) {
        val[currentvalpos] = (contextlen >> 8) & 0xff;
        currentvalpos++;
        val[currentvalpos] = contextlen & 0xff;
        currentvalpos++;
        if ((contextlen > 0) || (context != NULL)) {
            memcpy(val + currentvalpos, context, contextlen);
        }
    }
    if (memcmp(val, TLS_MD_CLIENT_FINISH_CONST,
               TLS_MD_CLIENT_FINISH_CONST_SIZE) == 0)
        goto err1;
    if (memcmp(val, TLS_MD_SERVER_FINISH_CONST,
               TLS_MD_SERVER_FINISH_CONST_SIZE) == 0)
        goto err1;
    if (memcmp(val, TLS_MD_MASTER_SECRET_CONST,
               TLS_MD_MASTER_SECRET_CONST_SIZE) == 0)
        goto err1;
    if (memcmp(val, TLS_MD_EXTENDED_MASTER_SECRET_CONST,
               TLS_MD_EXTENDED_MASTER_SECRET_CONST_SIZE) == 0)
        goto err1;
    if (memcmp(val, TLS_MD_KEY_EXPANSION_CONST,
               TLS_MD_KEY_EXPANSION_CONST_SIZE) == 0)
        goto err1;
    rv = tls1_PRF(s,
                  val, vallen,
                  NULL, 0,
                  NULL, 0,
                  NULL, 0,
                  NULL, 0,
                  s->session->master_key, s->session->master_key_length,
                  out, buff, olen);
    goto ret;
 err1:
    SSLerr(SSL_F_TLS1_EXPORT_KEYING_MATERIAL,
           SSL_R_TLS_ILLEGAL_EXPORTER_LABEL);
    rv = 0;
    goto ret;
 err2:
    SSLerr(SSL_F_TLS1_EXPORT_KEYING_MATERIAL, ERR_R_MALLOC_FAILURE);
    rv = 0;
 ret:
    CRYPTO_clear_free(val, vallen);
    CRYPTO_clear_free(buff, olen);
    return (rv);
}
['int tls1_export_keying_material(SSL *s, unsigned char *out, size_t olen,\n                                const char *label, size_t llen,\n                                const unsigned char *context,\n                                size_t contextlen, int use_context)\n{\n    unsigned char *buff;\n    unsigned char *val = NULL;\n    size_t vallen = 0, currentvalpos;\n    int rv;\n    buff = OPENSSL_malloc(olen);\n    if (buff == NULL)\n        goto err2;\n    vallen = llen + SSL3_RANDOM_SIZE * 2;\n    if (use_context) {\n        vallen += 2 + contextlen;\n    }\n    val = OPENSSL_malloc(vallen);\n    if (val == NULL)\n        goto err2;\n    currentvalpos = 0;\n    memcpy(val + currentvalpos, (unsigned char *)label, llen);\n    currentvalpos += llen;\n    memcpy(val + currentvalpos, s->s3->client_random, SSL3_RANDOM_SIZE);\n    currentvalpos += SSL3_RANDOM_SIZE;\n    memcpy(val + currentvalpos, s->s3->server_random, SSL3_RANDOM_SIZE);\n    currentvalpos += SSL3_RANDOM_SIZE;\n    if (use_context) {\n        val[currentvalpos] = (contextlen >> 8) & 0xff;\n        currentvalpos++;\n        val[currentvalpos] = contextlen & 0xff;\n        currentvalpos++;\n        if ((contextlen > 0) || (context != NULL)) {\n            memcpy(val + currentvalpos, context, contextlen);\n        }\n    }\n    if (memcmp(val, TLS_MD_CLIENT_FINISH_CONST,\n               TLS_MD_CLIENT_FINISH_CONST_SIZE) == 0)\n        goto err1;\n    if (memcmp(val, TLS_MD_SERVER_FINISH_CONST,\n               TLS_MD_SERVER_FINISH_CONST_SIZE) == 0)\n        goto err1;\n    if (memcmp(val, TLS_MD_MASTER_SECRET_CONST,\n               TLS_MD_MASTER_SECRET_CONST_SIZE) == 0)\n        goto err1;\n    if (memcmp(val, TLS_MD_EXTENDED_MASTER_SECRET_CONST,\n               TLS_MD_EXTENDED_MASTER_SECRET_CONST_SIZE) == 0)\n        goto err1;\n    if (memcmp(val, TLS_MD_KEY_EXPANSION_CONST,\n               TLS_MD_KEY_EXPANSION_CONST_SIZE) == 0)\n        goto err1;\n    rv = tls1_PRF(s,\n                  val, vallen,\n                  NULL, 0,\n                  NULL, 0,\n                  NULL, 0,\n                  NULL, 0,\n                  s->session->master_key, s->session->master_key_length,\n                  out, buff, olen);\n    goto ret;\n err1:\n    SSLerr(SSL_F_TLS1_EXPORT_KEYING_MATERIAL,\n           SSL_R_TLS_ILLEGAL_EXPORTER_LABEL);\n    rv = 0;\n    goto ret;\n err2:\n    SSLerr(SSL_F_TLS1_EXPORT_KEYING_MATERIAL, ERR_R_MALLOC_FAILURE);\n    rv = 0;\n ret:\n    CRYPTO_clear_free(val, vallen);\n    CRYPTO_clear_free(buff, olen);\n    return (rv);\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n    void *ret = NULL;\n    if (num <= 0)\n        return NULL;\n    allow_customize = 0;\n#ifdef CRYPTO_MDEBUG\n    if (call_malloc_debug) {\n        CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n        ret = malloc(num);\n        CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n    } else {\n        ret = malloc(num);\n    }\n#else\n    (void)file;\n    (void)line;\n    ret = malloc(num);\n#endif\n#ifndef OPENSSL_CPUID_OBJ\n    if (ret && (num > 2048)) {\n        extern unsigned char cleanse_ctr;\n        ((unsigned char *)ret)[0] = cleanse_ctr;\n    }\n#endif\n    return ret;\n}']