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


test/wpackettest.c:149:10: Call
147.       }
148.   
149.       if (!WPACKET_init_len(&pkt, buf, 1)
                ^
150.                   /*
151.                    * Should fail because we already consumed 1 byte with the

ssl/packet.c:134:1: Parameter `lenbytes`
  132.   }
  133.   
  134. > int WPACKET_init_len(WPACKET *pkt, BUF_MEM *buf, size_t lenbytes)
  135.   {
  136.       /* Internal API, so should not fail */

ssl/packet.c:145:12: Call
  143.       pkt->maxsize = maxmaxsize(lenbytes);
  144.   
  145.       return wpacket_intern_init_len(pkt, lenbytes);
                    ^
  146.   }
  147.   

ssl/packet.c:90:1: Parameter `lenbytes`
    88.   }
    89.   
    90. > static int wpacket_intern_init_len(WPACKET *pkt, size_t lenbytes)
    91.   {
    92.       unsigned char *lenchars;

ssl/packet.c:104:5: Assignment
    102.           return 1;
    103.   
    104.       pkt->subs->pwritten = lenbytes;
               ^
    105.       pkt->subs->lenbytes = lenbytes;
    106.   

test/wpackettest.c:174:17: Call
172.               || !WPACKET_put_bytes_u8(&pkt, 0xff)
173.               ||  WPACKET_put_bytes_u8(&pkt, 0xff)
174.               || !WPACKET_finish(&pkt)
                       ^
175.               || !WPACKET_get_total_written(&pkt, &written)
176.               ||  written != sizeof(simple2)

ssl/packet.c:255:1: Parameter `pkt->written`
  253.   }
  254.   
  255. > int WPACKET_finish(WPACKET *pkt)
  256.   {
  257.       int ret;

ssl/packet.c:266:11: Call
  264.           return 0;
  265.   
  266.       ret = wpacket_intern_close(pkt, pkt->subs, 1);
                   ^
  267.       if (ret) {
  268.           OPENSSL_free(pkt->subs);

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->written`
    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->pwritten`
    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:190:5: Binary operation: ([0, +oo] - 1):unsigned64 by call to `WPACKET_finish` 
    188.   static int wpacket_intern_close(WPACKET *pkt, WPACKET_SUB *sub, int doclose)
    189.   {
    190.       size_t packlen = pkt->written - sub->pwritten;
               ^
    191.   
    192.       if (packlen == 0

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_set_max_size(void)\n{\n    WPACKET pkt;\n    size_t written;\n    if (!WPACKET_init(&pkt, buf)\n            || !WPACKET_set_max_size(&pkt, SIZE_MAX)\n            || !WPACKET_set_max_size(&pkt, SIZE_MAX -1)\n            || !WPACKET_set_max_size(&pkt, SIZE_MAX)\n            || !WPACKET_finish(&pkt)) {\n        testfail("test_WPACKET_set_max_size():1 failed\\n", &pkt);\n        return 0;\n    }\n    if (!WPACKET_init_len(&pkt, buf, 1)\n            ||  WPACKET_set_max_size(&pkt, 0)\n            ||  WPACKET_set_max_size(&pkt, 0x0101)\n            || !WPACKET_set_max_size(&pkt, 0x0100)\n            || !WPACKET_set_max_size(&pkt, 0x01)\n            ||  WPACKET_put_bytes_u8(&pkt, 0xff)\n            || !WPACKET_set_max_size(&pkt, 0x02)\n            || !WPACKET_put_bytes_u8(&pkt, 0xff)\n            ||  WPACKET_put_bytes_u8(&pkt, 0xff)\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_set_max_size():2 failed\\n", &pkt);\n        return 0;\n    }\n    return 1;\n}', 'int WPACKET_init_len(WPACKET *pkt, BUF_MEM *buf, size_t lenbytes)\n{\n    assert(buf != NULL);\n    if (buf == NULL)\n        return 0;\n    pkt->staticbuf = NULL;\n    pkt->buf = buf;\n    pkt->maxsize = maxmaxsize(lenbytes);\n    return wpacket_intern_init_len(pkt, lenbytes);\n}', 'static int wpacket_intern_init_len(WPACKET *pkt, size_t lenbytes)\n{\n    unsigned char *lenchars;\n    pkt->curr = 0;\n    pkt->written = 0;\n    pkt->subs = OPENSSL_zalloc(sizeof(*pkt->subs));\n    if (pkt->subs == NULL)\n        return 0;\n    if (lenbytes == 0)\n        return 1;\n    pkt->subs->pwritten = lenbytes;\n    pkt->subs->lenbytes = lenbytes;\n    if (!WPACKET_allocate_bytes(pkt, lenbytes, &lenchars)) {\n        OPENSSL_free(pkt->subs);\n        pkt->subs = NULL;\n        return 0;\n    }\n    pkt->subs->packet_len = lenchars - GETBUF(pkt);\n    return 1;\n}', 'int WPACKET_finish(WPACKET *pkt)\n{\n    int ret;\n    if (pkt->subs == NULL || pkt->subs->parent != NULL)\n        return 0;\n    ret = wpacket_intern_close(pkt, pkt->subs, 1);\n    if (ret) {\n        OPENSSL_free(pkt->subs);\n        pkt->subs = NULL;\n    }\n    return ret;\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}']