From e5c858faf2f187e2cca56488f2e8dd48ca4b8d55 Mon Sep 17 00:00:00 2001 From: Batyrkhan Orynkul Date: Mon, 8 Jul 2019 13:30:30 -0700 Subject: [PATCH] Bug fixed in cn-cbor library When encoding cn_cbor structure before writing any chunk of bytes into buffer, library ensures that there is enough space to write current chunk. It is done by the following inequality: offset+length >= size. If inequality is true, then library decides that there is no enough space. However, if offset+length == size then there is still enough space to write a chunk of size length. --- src/cn-encoder.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cn-encoder.c b/src/cn-encoder.c index d8a4d49..ffaf3e8 100644 --- a/src/cn-encoder.c +++ b/src/cn-encoder.c @@ -35,7 +35,7 @@ typedef struct _write_state ssize_t size; } cn_write_state; -#define ensure_writable(sz) if ((ws->offset<0) || (ws->offset + (sz) >= ws->size)) { \ +#define ensure_writable(sz) if ((ws->offset<0) || (ws->offset + (sz) > ws->size)) { \ ws->offset = -1; \ return; \ }