static int
dtls1_process_out_of_seq_message(SSL *s, const struct hm_header_st *msg_hdr,
                                 int *ok)
{
    int i = -1;
    hm_fragment *frag = NULL;
    pitem *item = NULL;
    unsigned char seq64be[8];
    unsigned long frag_len = msg_hdr->frag_len;
    if ((msg_hdr->frag_off + frag_len) > msg_hdr->msg_len)
        goto err;
    memset(seq64be, 0, sizeof(seq64be));
    seq64be[6] = (unsigned char)(msg_hdr->seq >> 8);
    seq64be[7] = (unsigned char)msg_hdr->seq;
    item = pqueue_find(s->d1->buffered_messages, seq64be);
    if (item != NULL && frag_len != msg_hdr->msg_len)
        item = NULL;
    if (msg_hdr->seq <= s->d1->handshake_read_seq ||
        msg_hdr->seq > s->d1->handshake_read_seq + 10 || item != NULL ||
        (s->d1->handshake_read_seq == 0 && msg_hdr->type == SSL3_MT_FINISHED))
    {
        unsigned char devnull[256];
        while (frag_len) {
            i = s->method->ssl_read_bytes(s, SSL3_RT_HANDSHAKE, NULL,
                                          devnull,
                                          frag_len >
                                          sizeof(devnull) ? sizeof(devnull) :
                                          frag_len, 0);
            if (i <= 0)
                goto err;
            frag_len -= i;
        }
    } else {
        if (frag_len != msg_hdr->msg_len)
            return dtls1_reassemble_fragment(s, msg_hdr, ok);
        if (frag_len > dtls1_max_handshake_message_len(s))
            goto err;
        frag = dtls1_hm_fragment_new(frag_len, 0);
        if (frag == NULL)
            goto err;
        memcpy(&(frag->msg_header), msg_hdr, sizeof(*msg_hdr));
        if (frag_len) {
            i = s->method->ssl_read_bytes(s, SSL3_RT_HANDSHAKE, NULL,
                                          frag->fragment, frag_len, 0);
            if ((unsigned long)i != frag_len)
                i = -1;
            if (i <= 0)
                goto err;
        }
        item = pitem_new(seq64be, frag);
        if (item == NULL)
            goto err;
        item = pqueue_insert(s->d1->buffered_messages, item);
        OPENSSL_assert(item != NULL);
    }
    return DTLS1_HM_FRAGMENT_RETRY;
 err:
    if (item == NULL)
        dtls1_hm_fragment_free(frag);
    *ok = 0;
    return i;
}
['static int\ndtls1_process_out_of_seq_message(SSL *s, const struct hm_header_st *msg_hdr,\n                                 int *ok)\n{\n    int i = -1;\n    hm_fragment *frag = NULL;\n    pitem *item = NULL;\n    unsigned char seq64be[8];\n    unsigned long frag_len = msg_hdr->frag_len;\n    if ((msg_hdr->frag_off + frag_len) > msg_hdr->msg_len)\n        goto err;\n    memset(seq64be, 0, sizeof(seq64be));\n    seq64be[6] = (unsigned char)(msg_hdr->seq >> 8);\n    seq64be[7] = (unsigned char)msg_hdr->seq;\n    item = pqueue_find(s->d1->buffered_messages, seq64be);\n    if (item != NULL && frag_len != msg_hdr->msg_len)\n        item = NULL;\n    if (msg_hdr->seq <= s->d1->handshake_read_seq ||\n        msg_hdr->seq > s->d1->handshake_read_seq + 10 || item != NULL ||\n        (s->d1->handshake_read_seq == 0 && msg_hdr->type == SSL3_MT_FINISHED))\n    {\n        unsigned char devnull[256];\n        while (frag_len) {\n            i = s->method->ssl_read_bytes(s, SSL3_RT_HANDSHAKE, NULL,\n                                          devnull,\n                                          frag_len >\n                                          sizeof(devnull) ? sizeof(devnull) :\n                                          frag_len, 0);\n            if (i <= 0)\n                goto err;\n            frag_len -= i;\n        }\n    } else {\n        if (frag_len != msg_hdr->msg_len)\n            return dtls1_reassemble_fragment(s, msg_hdr, ok);\n        if (frag_len > dtls1_max_handshake_message_len(s))\n            goto err;\n        frag = dtls1_hm_fragment_new(frag_len, 0);\n        if (frag == NULL)\n            goto err;\n        memcpy(&(frag->msg_header), msg_hdr, sizeof(*msg_hdr));\n        if (frag_len) {\n            i = s->method->ssl_read_bytes(s, SSL3_RT_HANDSHAKE, NULL,\n                                          frag->fragment, frag_len, 0);\n            if ((unsigned long)i != frag_len)\n                i = -1;\n            if (i <= 0)\n                goto err;\n        }\n        item = pitem_new(seq64be, frag);\n        if (item == NULL)\n            goto err;\n        item = pqueue_insert(s->d1->buffered_messages, item);\n        OPENSSL_assert(item != NULL);\n    }\n    return DTLS1_HM_FRAGMENT_RETRY;\n err:\n    if (item == NULL)\n        dtls1_hm_fragment_free(frag);\n    *ok = 0;\n    return i;\n}', 'pitem *pqueue_find(pqueue_s *pq, unsigned char *prio64be)\n{\n    pitem *next;\n    pitem *found = NULL;\n    if (pq->items == NULL)\n        return NULL;\n    for (next = pq->items; next->next != NULL; next = next->next) {\n        if (memcmp(next->priority, prio64be, 8) == 0) {\n            found = next;\n            break;\n        }\n    }\n    if (memcmp(next->priority, prio64be, 8) == 0)\n        found = next;\n    if (!found)\n        return NULL;\n    return found;\n}', 'static unsigned long dtls1_max_handshake_message_len(const SSL *s)\n{\n    unsigned long max_len =\n        DTLS1_HM_HEADER_LENGTH + SSL3_RT_MAX_ENCRYPTED_LENGTH;\n    if (max_len < (unsigned long)s->max_cert_list)\n        return s->max_cert_list;\n    return max_len;\n}', 'static hm_fragment *dtls1_hm_fragment_new(unsigned long frag_len,\n                                          int reassembly)\n{\n    hm_fragment *frag = NULL;\n    unsigned char *buf = NULL;\n    unsigned char *bitmask = NULL;\n    frag = OPENSSL_malloc(sizeof(*frag));\n    if (frag == NULL)\n        return NULL;\n    if (frag_len) {\n        buf = OPENSSL_malloc(frag_len);\n        if (buf == NULL) {\n            OPENSSL_free(frag);\n            return NULL;\n        }\n    }\n    frag->fragment = buf;\n    if (reassembly) {\n        bitmask = OPENSSL_zalloc(RSMBLY_BITMASK_SIZE(frag_len));\n        if (bitmask == NULL) {\n            OPENSSL_free(buf);\n            OPENSSL_free(frag);\n            return NULL;\n        }\n    }\n    frag->reassembly = bitmask;\n    return frag;\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#ifndef OPENSSL_NO_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}', 'pitem *pitem_new(unsigned char *prio64be, void *data)\n{\n    pitem *item = OPENSSL_malloc(sizeof(*item));\n    if (item == NULL)\n        return NULL;\n    memcpy(item->priority, prio64be, sizeof(item->priority));\n    item->data = data;\n    item->next = NULL;\n    return item;\n}']