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


test/wpackettest.c:57:10: Call
55.   
56.       /* Now try with a one byte length prefix */
57.       if (!TEST_true(WPACKET_init_len(&pkt, buf, 1))
               ^
58.               || !TEST_true(WPACKET_put_bytes_u8(&pkt, 0xff))
59.               || !TEST_true(WPACKET_finish(&pkt))

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

test/wpackettest.c:58:17: Call
56.       /* Now try with a one byte length prefix */
57.       if (!TEST_true(WPACKET_init_len(&pkt, buf, 1))
58.               || !TEST_true(WPACKET_put_bytes_u8(&pkt, 0xff))
                      ^
59.               || !TEST_true(WPACKET_finish(&pkt))
60.               || !TEST_true(WPACKET_get_total_written(&pkt, &written))

crypto/packet.c:309:1: Parameter `pkt->written`
  307.   }
  308.   
  309. > int WPACKET_put_bytes__(WPACKET *pkt, unsigned int val, size_t size)
  310.   {
  311.       unsigned char *data;

test/wpackettest.c:59:17: Call
57.       if (!TEST_true(WPACKET_init_len(&pkt, buf, 1))
58.               || !TEST_true(WPACKET_put_bytes_u8(&pkt, 0xff))
59.               || !TEST_true(WPACKET_finish(&pkt))
                      ^
60.               || !TEST_true(WPACKET_get_total_written(&pkt, &written))
61.               || !TEST_mem_eq(buf->data, written, simple2, sizeof(simple2)))

crypto/packet.c:252:1: Parameter `pkt->written`
  250.   }
  251.   
  252. > int WPACKET_finish(WPACKET *pkt)
  253.   {
  254.       int ret;

crypto/packet.c:263:11: Call
  261.           return 0;
  262.   
  263.       ret = wpacket_intern_close(pkt, pkt->subs, 1);
                   ^
  264.       if (ret) {
  265.           OPENSSL_free(pkt->subs);

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

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

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

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

crypto/packet.c:188:5: Binary operation: ([0, +oo] - 1):unsigned64 by call to `WPACKET_finish` 
    186.   static int wpacket_intern_close(WPACKET *pkt, WPACKET_SUB *sub, int doclose)
    187.   {
    188.       size_t packlen = pkt->written - sub->pwritten;
               ^
    189.   
    190.       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_init(void)\n{\n    WPACKET pkt;\n    int i;\n    size_t written;\n    unsigned char sbuf[3];\n    if (!TEST_true(WPACKET_init(&pkt, buf))\n            || !TEST_true(WPACKET_put_bytes_u8(&pkt, 0xff))\n            || !TEST_false(WPACKET_close(&pkt))\n            || !TEST_true(WPACKET_finish(&pkt))\n            || !TEST_false(WPACKET_close(&pkt))\n            || !TEST_false(WPACKET_finish(&pkt))\n            || !TEST_true(WPACKET_get_total_written(&pkt, &written))\n            || !TEST_mem_eq(buf->data, written, simple1, sizeof(simple1)))\n        return cleanup(&pkt);\n    if (!TEST_true(WPACKET_init_len(&pkt, buf, 1))\n            || !TEST_true(WPACKET_put_bytes_u8(&pkt, 0xff))\n            || !TEST_true(WPACKET_finish(&pkt))\n            || !TEST_true(WPACKET_get_total_written(&pkt, &written))\n            || !TEST_mem_eq(buf->data, written, simple2, sizeof(simple2)))\n        return cleanup(&pkt);\n    if (!TEST_true(WPACKET_init_len(&pkt, buf, 4))\n            || !TEST_true(WPACKET_put_bytes_u8(&pkt, 0xff))\n            || !TEST_true(WPACKET_finish(&pkt))\n            || !TEST_true(WPACKET_get_total_written(&pkt, &written))\n            || !TEST_mem_eq(buf->data, written, simple3, sizeof(simple3)))\n        return cleanup(&pkt);\n    if (!TEST_true(WPACKET_init_len(&pkt, buf, 1)))\n        return cleanup(&pkt);\n    for (i = 1; i < 257; i++) {\n        if (!TEST_int_eq(WPACKET_put_bytes_u8(&pkt, 0xff), i < 256))\n            return cleanup(&pkt);\n    }\n    if (!TEST_true(WPACKET_finish(&pkt)))\n        return cleanup(&pkt);\n    if (!TEST_true(WPACKET_init_static_len(&pkt, sbuf, sizeof(sbuf), 0))\n            || !TEST_true(WPACKET_put_bytes_u24(&pkt, 0xffffff))\n            || !TEST_false(WPACKET_put_bytes_u8(&pkt, 0xff))\n            || !TEST_true(WPACKET_finish(&pkt))\n            || !TEST_true(WPACKET_get_total_written(&pkt, &written))\n            || !TEST_mem_eq(sbuf, written, fixed, sizeof(sbuf))\n            || !TEST_true(WPACKET_init_static_len(&pkt, sbuf, sizeof(sbuf), 1))\n            || !TEST_true(WPACKET_put_bytes_u16(&pkt, 0xfeff))\n            || !TEST_false(WPACKET_put_bytes_u8(&pkt, 0xff))\n            || !TEST_true(WPACKET_finish(&pkt))\n            || !TEST_true(WPACKET_get_total_written(&pkt, &written))\n            || !TEST_mem_eq(sbuf, written, alloc, sizeof(alloc)))\n        return cleanup(&pkt);\n    return 1;\n}', 'int WPACKET_init_len(WPACKET *pkt, BUF_MEM *buf, size_t lenbytes)\n{\n    if (!ossl_assert(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}', 'int WPACKET_put_bytes__(WPACKET *pkt, unsigned int val, size_t size)\n{\n    unsigned char *data;\n    if (!ossl_assert(size <= sizeof(unsigned int))\n            || !WPACKET_allocate_bytes(pkt, size, &data)\n            || !put_value(data, val, size))\n        return 0;\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}']