test/wpackettest.c:212: error: INTEGER_OVERFLOW_L2
  ([0, +oo] - [0, 1]):unsigned64 by call to `WPACKET_close`.
Showing all 11 steps of the trace


test/wpackettest.c:210:17: Call
208.      /* Single sub-packet with length prefix */
209.       if (!WPACKET_init(&pkt, buf)
210.               || !WPACKET_start_sub_packet_u8(&pkt)
                       ^
211.               || !WPACKET_put_bytes_u8(&pkt, 0xff)
212.               || !WPACKET_close(&pkt)

ssl/packet.c:275:1: Parameter `lenbytes`
  273.   }
  274.   
  275. > int WPACKET_start_sub_packet_len__(WPACKET *pkt, size_t lenbytes)
  276.   {
  277.       WPACKET_SUB *sub;

ssl/packet.c:292:5: Assignment
  290.       pkt->subs = sub;
  291.       sub->pwritten = pkt->written + lenbytes;
  292.       sub->lenbytes = lenbytes;
             ^
  293.   
  294.       if (lenbytes == 0) {

test/wpackettest.c:212:17: Call
210.               || !WPACKET_start_sub_packet_u8(&pkt)
211.               || !WPACKET_put_bytes_u8(&pkt, 0xff)
212.               || !WPACKET_close(&pkt)
                       ^
213.               || !WPACKET_finish(&pkt)
214.               || !WPACKET_get_total_written(&pkt, &written)

ssl/packet.c:243:1: Parameter `pkt->curr`
  241.   }
  242.   
  243. > int WPACKET_close(WPACKET *pkt)
  244.   {
  245.       /*

ssl/packet.c:252:12: Call
  250.           return 0;
  251.   
  252.       return wpacket_intern_close(pkt, pkt->subs, 1);
                    ^
  253.   }
  254.   

ssl/packet.c:188:1: <LHS trace>
186.    * (i.e. it fills in all the lengths), but doesn't actually close anything.
187.    */
188. > static int wpacket_intern_close(WPACKET *pkt, WPACKET_SUB *sub, int doclose)
189.   {
190.       size_t packlen = pkt->written - sub->pwritten;

ssl/packet.c:188:1: Parameter `pkt->curr`
    186.    * (i.e. it fills in all the lengths), but doesn't actually close anything.
    187.    */
    188. > static int wpacket_intern_close(WPACKET *pkt, WPACKET_SUB *sub, int doclose)
    189.   {
    190.       size_t packlen = pkt->written - sub->pwritten;

ssl/packet.c:188:1: <RHS trace>
186.    * (i.e. it fills in all the lengths), but doesn't actually close anything.
187.    */
188. > static int wpacket_intern_close(WPACKET *pkt, WPACKET_SUB *sub, int doclose)
189.   {
190.       size_t packlen = pkt->written - sub->pwritten;

ssl/packet.c:188:1: Parameter `sub->lenbytes`
    186.    * (i.e. it fills in all the lengths), but doesn't actually close anything.
    187.    */
    188. > static int wpacket_intern_close(WPACKET *pkt, WPACKET_SUB *sub, int doclose)
    189.   {
    190.       size_t packlen = pkt->written - sub->pwritten;

ssl/packet.c:203:13: Binary operation: ([0, +oo] - [0, 1]):unsigned64 by call to `WPACKET_close` 
    201.   
    202.           /* Deallocate any bytes allocated for the length of the WPACKET */
    203.           if ((pkt->curr - sub->lenbytes) == sub->packet_len) {
                       ^
    204.               pkt->written -= sub->lenbytes;
    205.               pkt->curr -= sub->lenbytes;

static int wpacket_intern_close(WPACKET *pkt, WPACKET_SUB *sub, int doclose)
{
    size_t packlen = pkt->written - sub->pwritten;
    if (packlen == 0
            && (sub->flags & WPACKET_FLAGS_NON_ZERO_LENGTH) != 0)
        return 0;
    if (packlen == 0
            && sub->flags & WPACKET_FLAGS_ABANDON_ON_ZERO_LENGTH) {
        if (!doclose)
            return 0;
        if ((pkt->curr - sub->lenbytes) == sub->packet_len) {
            pkt->written -= sub->lenbytes;
            pkt->curr -= sub->lenbytes;
        }
        sub->packet_len = 0;
        sub->lenbytes = 0;
    }
    if (sub->lenbytes > 0
                && !put_value(&GETBUF(pkt)[sub->packet_len], packlen,
                              sub->lenbytes))
            return 0;
    if (doclose) {
        pkt->subs = sub->parent;
        OPENSSL_free(sub);
    }
    return 1;
}
['static int test_WPACKET_start_sub_packet(void)\n{\n    WPACKET pkt;\n    size_t written;\n    size_t len;\n    if (!WPACKET_init(&pkt, buf)\n            || !WPACKET_start_sub_packet(&pkt)\n            || !WPACKET_put_bytes_u8(&pkt, 0xff)\n            ||  WPACKET_finish(&pkt)\n            || !WPACKET_close(&pkt)\n            ||  WPACKET_close(&pkt)\n            || !WPACKET_finish(&pkt)\n            || !WPACKET_get_total_written(&pkt, &written)\n            ||  written != sizeof(simple1)\n            ||  memcmp(buf->data, &simple1, written) != 0) {\n        testfail("test_WPACKET_start_sub_packet():1 failed\\n", &pkt);\n        return 0;\n    }\n    if (!WPACKET_init(&pkt, buf)\n            || !WPACKET_start_sub_packet_u8(&pkt)\n            || !WPACKET_put_bytes_u8(&pkt, 0xff)\n            || !WPACKET_close(&pkt)\n            || !WPACKET_finish(&pkt)\n            || !WPACKET_get_total_written(&pkt, &written)\n            ||  written != sizeof(simple2)\n            ||  memcmp(buf->data, &simple2, written) != 0) {\n        testfail("test_WPACKET_start_sub_packet():2 failed\\n", &pkt);\n        return 0;\n    }\n    if (!WPACKET_init(&pkt, buf)\n            || !WPACKET_start_sub_packet_u8(&pkt)\n            || !WPACKET_put_bytes_u8(&pkt, 0xff)\n            || !WPACKET_start_sub_packet_u8(&pkt)\n            || !WPACKET_put_bytes_u8(&pkt, 0xff)\n            || !WPACKET_get_length(&pkt, &len)\n            || len != 1\n            || !WPACKET_close(&pkt)\n            || !WPACKET_get_length(&pkt, &len)\n            || len != 3\n            || !WPACKET_close(&pkt)\n            || !WPACKET_finish(&pkt)\n            || !WPACKET_get_total_written(&pkt, &written)\n            ||  written != sizeof(nestedsub)\n            ||  memcmp(buf->data, &nestedsub, written) != 0) {\n        testfail("test_WPACKET_start_sub_packet():3 failed\\n", &pkt);\n        return 0;\n    }\n    if (!WPACKET_init(&pkt, buf)\n            || !WPACKET_start_sub_packet_u8(&pkt)\n            || !WPACKET_put_bytes_u8(&pkt, 0xff)\n            || !WPACKET_close(&pkt)\n            || !WPACKET_start_sub_packet_u8(&pkt)\n            || !WPACKET_put_bytes_u8(&pkt, 0xff)\n            || !WPACKET_close(&pkt)\n            || !WPACKET_finish(&pkt)\n            || !WPACKET_get_total_written(&pkt, &written)\n            ||  written != sizeof(seqsub)\n            ||  memcmp(buf->data, &seqsub, written) != 0) {\n        testfail("test_WPACKET_start_sub_packet():4 failed\\n", &pkt);\n        return 0;\n    }\n    if (!WPACKET_init(&pkt, buf)\n            || !WPACKET_start_sub_packet_u8(&pkt)\n            || !WPACKET_put_bytes_u8(&pkt, 0xff)\n            || !WPACKET_start_sub_packet_u8(&pkt)\n            || !WPACKET_put_bytes_u8(&pkt, 0xff)\n            || !WPACKET_get_length(&pkt, &len)\n            || len != 1\n            || !WPACKET_close(&pkt)\n            || !WPACKET_get_length(&pkt, &len)\n            || len != 3\n            || !WPACKET_close(&pkt)\n            || !WPACKET_fill_lengths(&pkt)\n            || !WPACKET_get_total_written(&pkt, &written)\n            ||  written != sizeof(nestedsub)\n            ||  memcmp(buf->data, &nestedsub, written) != 0\n            || !WPACKET_finish(&pkt)) {\n        testfail("test_WPACKET_start_sub_packet():5 failed\\n", &pkt);\n        return 0;\n    }\n    return 1;\n}', 'int WPACKET_start_sub_packet_len__(WPACKET *pkt, size_t lenbytes)\n{\n    WPACKET_SUB *sub;\n    unsigned char *lenchars;\n    assert(pkt->subs != NULL);\n    if (pkt->subs == NULL)\n        return 0;\n    sub = OPENSSL_zalloc(sizeof(*sub));\n    if (sub == NULL)\n        return 0;\n    sub->parent = pkt->subs;\n    pkt->subs = sub;\n    sub->pwritten = pkt->written + lenbytes;\n    sub->lenbytes = lenbytes;\n    if (lenbytes == 0) {\n        sub->packet_len = 0;\n        return 1;\n    }\n    if (!WPACKET_allocate_bytes(pkt, lenbytes, &lenchars))\n        return 0;\n    sub->packet_len = lenchars - GETBUF(pkt);\n    return 1;\n}', 'int WPACKET_close(WPACKET *pkt)\n{\n    if (pkt->subs == NULL || pkt->subs->parent == NULL)\n        return 0;\n    return wpacket_intern_close(pkt, pkt->subs, 1);\n}', 'static int wpacket_intern_close(WPACKET *pkt, WPACKET_SUB *sub, int doclose)\n{\n    size_t packlen = pkt->written - sub->pwritten;\n    if (packlen == 0\n            && (sub->flags & WPACKET_FLAGS_NON_ZERO_LENGTH) != 0)\n        return 0;\n    if (packlen == 0\n            && sub->flags & WPACKET_FLAGS_ABANDON_ON_ZERO_LENGTH) {\n        if (!doclose)\n            return 0;\n        if ((pkt->curr - sub->lenbytes) == sub->packet_len) {\n            pkt->written -= sub->lenbytes;\n            pkt->curr -= sub->lenbytes;\n        }\n        sub->packet_len = 0;\n        sub->lenbytes = 0;\n    }\n    if (sub->lenbytes > 0\n                && !put_value(&GETBUF(pkt)[sub->packet_len], packlen,\n                              sub->lenbytes))\n            return 0;\n    if (doclose) {\n        pkt->subs = sub->parent;\n        OPENSSL_free(sub);\n    }\n    return 1;\n}']