From 0c07860d8c0160fea35c59fc5d43b948f354359e Mon Sep 17 00:00:00 2001 From: Michael Jeanson Date: Thu, 24 Mar 2022 14:29:36 -0400 Subject: [PATCH] Update vendored msgpack-c to 4.0.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The upstream changes from 3.3.0 to 4.0.0 : * Fix and improve alignment logic (#962) * Fix iovec name conflict (#953) * Fix empty string print (#942) * Fix buffer ptr size (#899) * Fix UB. Check null pointer before using memcpy() (#890) Change-Id: Ifc4d7de43d0f11d6331d98d7cfa93227f8b756bc Signed-off-by: Michael Jeanson Signed-off-by: Jérémie Galarneau --- src/vendor/msgpack/Makefile.am | 1 - src/vendor/msgpack/fbuffer.h | 4 ++++ src/vendor/msgpack/lttng-config.h | 2 ++ src/vendor/msgpack/objectc.c | 4 +++- src/vendor/msgpack/pack_template.h | 2 ++ src/vendor/msgpack/predef.h | 24 ------------------------ src/vendor/msgpack/sbuffer.h | 5 +++++ src/vendor/msgpack/sysdep.h | 7 +++++++ src/vendor/msgpack/version_master.h | 4 ++-- src/vendor/msgpack/vrefbuffer.c | 22 +++++++++++----------- src/vendor/msgpack/vrefbuffer.h | 18 ++++++++++++------ src/vendor/msgpack/zbuffer.h | 4 ++++ src/vendor/msgpack/zone.h | 6 +++--- 13 files changed, 55 insertions(+), 48 deletions(-) delete mode 100644 src/vendor/msgpack/predef.h diff --git a/src/vendor/msgpack/Makefile.am b/src/vendor/msgpack/Makefile.am index 6666b6108..7ad4f6671 100644 --- a/src/vendor/msgpack/Makefile.am +++ b/src/vendor/msgpack/Makefile.am @@ -16,7 +16,6 @@ libmsgpack_la_SOURCES = \ pack_define.h \ pack.h \ pack_template.h \ - predef.h \ sbuffer.h \ sysdep.h \ timestamp.h \ diff --git a/src/vendor/msgpack/fbuffer.h b/src/vendor/msgpack/fbuffer.h index d478008c8..5c847dd97 100644 --- a/src/vendor/msgpack/fbuffer.h +++ b/src/vendor/msgpack/fbuffer.h @@ -11,6 +11,7 @@ #define MSGPACK_FBUFFER_H #include +#include #ifdef __cplusplus extern "C" { @@ -25,6 +26,9 @@ extern "C" { static inline int msgpack_fbuffer_write(void* data, const char* buf, size_t len) { + assert(buf || len == 0); + if(!buf) return 0; + return (1 == fwrite(buf, len, 1, (FILE *)data)) ? 0 : -1; } diff --git a/src/vendor/msgpack/lttng-config.h b/src/vendor/msgpack/lttng-config.h index 54b14682e..d2f49b281 100644 --- a/src/vendor/msgpack/lttng-config.h +++ b/src/vendor/msgpack/lttng-config.h @@ -13,7 +13,9 @@ #if BYTE_ORDER == LITTLE_ENDIAN #define MSGPACK_ENDIAN_LITTLE_BYTE 1 +#define MSGPACK_ENDIAN_BIG_BYTE 0 #elif BYTE_ORDER == BIG_ENDIAN +#define MSGPACK_ENDIAN_LITTLE_BYTE 0 #define MSGPACK_ENDIAN_BIG_BYTE 1 #endif diff --git a/src/vendor/msgpack/objectc.c b/src/vendor/msgpack/objectc.c index 6086bd618..399b18fb3 100644 --- a/src/vendor/msgpack/objectc.c +++ b/src/vendor/msgpack/objectc.c @@ -331,7 +331,9 @@ int msgpack_object_print_buffer(char *buffer, size_t buffer_size, msgpack_object case MSGPACK_OBJECT_STR: MSGPACK_CHECKED_CALL(ret, snprintf, aux_buffer, aux_buffer_size, "\""); - MSGPACK_CHECKED_CALL(ret, snprintf, aux_buffer, aux_buffer_size, "%.*s", (int)o.via.str.size, o.via.str.ptr); + if (o.via.str.size > 0) { + MSGPACK_CHECKED_CALL(ret, snprintf, aux_buffer, aux_buffer_size, "%.*s", (int)o.via.str.size, o.via.str.ptr); + } MSGPACK_CHECKED_CALL(ret, snprintf, aux_buffer, aux_buffer_size, "\""); break; diff --git a/src/vendor/msgpack/pack_template.h b/src/vendor/msgpack/pack_template.h index ac112e1d9..1ad8686ba 100644 --- a/src/vendor/msgpack/pack_template.h +++ b/src/vendor/msgpack/pack_template.h @@ -8,6 +8,8 @@ * http://www.boost.org/LICENSE_1_0.txt) */ +#include "vendor/msgpack/lttng-config.h" + #if MSGPACK_ENDIAN_LITTLE_BYTE #define TAKE8_8(d) ((uint8_t*)&d)[0] #define TAKE8_16(d) ((uint8_t*)&d)[0] diff --git a/src/vendor/msgpack/predef.h b/src/vendor/msgpack/predef.h deleted file mode 100644 index b2309eef7..000000000 --- a/src/vendor/msgpack/predef.h +++ /dev/null @@ -1,24 +0,0 @@ -/* -Copyright Rene Rivera 2008-2015 -Distributed under the Boost Software License, Version 1.0. -(See accompanying file LICENSE_1_0.txt or copy at -http://www.boost.org/LICENSE_1_0.txt) -*/ - -#if !defined(MSGPACK_PREDEF_H) || defined(MSGPACK_PREDEF_INTERNAL_GENERATE_TESTS) -#ifndef MSGPACK_PREDEF_H -#define MSGPACK_PREDEF_H -#endif - -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#endif diff --git a/src/vendor/msgpack/sbuffer.h b/src/vendor/msgpack/sbuffer.h index c494bae77..572d8f27e 100644 --- a/src/vendor/msgpack/sbuffer.h +++ b/src/vendor/msgpack/sbuffer.h @@ -12,6 +12,7 @@ #include #include +#include #ifdef __cplusplus extern "C" { @@ -60,6 +61,9 @@ static inline int msgpack_sbuffer_write(void* data, const char* buf, size_t len) { msgpack_sbuffer* sbuf = (msgpack_sbuffer*)data; + assert(buf || len == 0); + if(!buf) return 0; + if(sbuf->alloc - sbuf->size < len) { void* tmp; size_t nsize = (sbuf->alloc) ? @@ -83,6 +87,7 @@ static inline int msgpack_sbuffer_write(void* data, const char* buf, size_t len) memcpy(sbuf->data + sbuf->size, buf, len); sbuf->size += len; + return 0; } diff --git a/src/vendor/msgpack/sysdep.h b/src/vendor/msgpack/sysdep.h index ad5f615aa..9cbb7a1db 100644 --- a/src/vendor/msgpack/sysdep.h +++ b/src/vendor/msgpack/sysdep.h @@ -28,6 +28,13 @@ typedef unsigned __int32 uint32_t; typedef signed __int64 int64_t; typedef unsigned __int64 uint64_t; +# if defined(_WIN64) + typedef signed __int64 intptr_t; + typedef unsigned __int64 uintptr_t; +# else + typedef signed __int32 intptr_t; + typedef unsigned __int32 uintptr_t; +# endif #elif defined(_MSC_VER) // && _MSC_VER >= 1600 # include #else diff --git a/src/vendor/msgpack/version_master.h b/src/vendor/msgpack/version_master.h index 9db6023e7..763c732c7 100644 --- a/src/vendor/msgpack/version_master.h +++ b/src/vendor/msgpack/version_master.h @@ -1,3 +1,3 @@ -#define MSGPACK_VERSION_MAJOR 3 -#define MSGPACK_VERSION_MINOR 3 +#define MSGPACK_VERSION_MAJOR 4 +#define MSGPACK_VERSION_MINOR 0 #define MSGPACK_VERSION_REVISION 0 diff --git a/src/vendor/msgpack/vrefbuffer.c b/src/vendor/msgpack/vrefbuffer.c index 9c7b3b549..a693bd177 100644 --- a/src/vendor/msgpack/vrefbuffer.c +++ b/src/vendor/msgpack/vrefbuffer.c @@ -22,7 +22,7 @@ bool msgpack_vrefbuffer_init(msgpack_vrefbuffer* vbuf, size_t ref_size, size_t chunk_size) { size_t nfirst; - struct iovec* array; + msgpack_iovec* array; msgpack_vrefbuffer_chunk* chunk; if (ref_size == 0) { @@ -40,11 +40,11 @@ bool msgpack_vrefbuffer_init(msgpack_vrefbuffer* vbuf, return false; } - nfirst = (sizeof(struct iovec) < 72/2) ? - 72 / sizeof(struct iovec) : 8; + nfirst = (sizeof(msgpack_iovec) < 72/2) ? + 72 / sizeof(msgpack_iovec) : 8; - array = (struct iovec*)malloc( - sizeof(struct iovec) * nfirst); + array = (msgpack_iovec*)malloc( + sizeof(msgpack_iovec) * nfirst); if(array == NULL) { return false; } @@ -114,8 +114,8 @@ int msgpack_vrefbuffer_append_ref(msgpack_vrefbuffer* vbuf, const size_t nused = (size_t)(vbuf->tail - vbuf->array); const size_t nnext = nused * 2; - struct iovec* nvec = (struct iovec*)realloc( - vbuf->array, sizeof(struct iovec)*nnext); + msgpack_iovec* nvec = (msgpack_iovec*)realloc( + vbuf->array, sizeof(msgpack_iovec)*nnext); if(nvec == NULL) { return -1; } @@ -194,7 +194,7 @@ int msgpack_vrefbuffer_migrate(msgpack_vrefbuffer* vbuf, msgpack_vrefbuffer* to) { const size_t nused = (size_t)(vbuf->tail - vbuf->array); if(to->tail + nused < vbuf->end) { - struct iovec* nvec; + msgpack_iovec* nvec; const size_t tosize = (size_t)(to->tail - to->array); const size_t reqsize = nused + tosize; size_t nnext = (size_t)(to->end - to->array) * 2; @@ -207,8 +207,8 @@ int msgpack_vrefbuffer_migrate(msgpack_vrefbuffer* vbuf, msgpack_vrefbuffer* to) nnext = tmp_nnext; } - nvec = (struct iovec*)realloc( - to->array, sizeof(struct iovec)*nnext); + nvec = (msgpack_iovec*)realloc( + to->array, sizeof(msgpack_iovec)*nnext); if(nvec == NULL) { free(empty); return -1; @@ -219,7 +219,7 @@ int msgpack_vrefbuffer_migrate(msgpack_vrefbuffer* vbuf, msgpack_vrefbuffer* to) to->tail = nvec + tosize; } - memcpy(to->tail, vbuf->array, sizeof(struct iovec)*nused); + memcpy(to->tail, vbuf->array, sizeof(msgpack_iovec)*nused); to->tail += nused; vbuf->tail = vbuf->array; diff --git a/src/vendor/msgpack/vrefbuffer.h b/src/vendor/msgpack/vrefbuffer.h index ab51aefa3..c2633052b 100644 --- a/src/vendor/msgpack/vrefbuffer.h +++ b/src/vendor/msgpack/vrefbuffer.h @@ -12,14 +12,17 @@ #include "zone.h" #include +#include #if defined(unix) || defined(__unix) || defined(__linux__) || defined(__APPLE__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__QNX__) || defined(__QNXTO__) || defined(__HAIKU__) #include +typedef struct iovec msgpack_iovec; #else -struct iovec { +struct msgpack_iovec { void *iov_base; size_t iov_len; }; +typedef struct msgpack_iovec msgpack_iovec; #endif #ifdef __cplusplus @@ -43,9 +46,9 @@ typedef struct msgpack_vrefbuffer_inner_buffer { } msgpack_vrefbuffer_inner_buffer; typedef struct msgpack_vrefbuffer { - struct iovec* tail; - struct iovec* end; - struct iovec* array; + msgpack_iovec* tail; + msgpack_iovec* end; + msgpack_iovec* array; size_t chunk_size; size_t ref_size; @@ -73,7 +76,7 @@ static inline void msgpack_vrefbuffer_free(msgpack_vrefbuffer* vbuf); static inline int msgpack_vrefbuffer_write(void* data, const char* buf, size_t len); -static inline const struct iovec* msgpack_vrefbuffer_vec(const msgpack_vrefbuffer* vref); +static inline const msgpack_iovec* msgpack_vrefbuffer_vec(const msgpack_vrefbuffer* vref); static inline size_t msgpack_vrefbuffer_veclen(const msgpack_vrefbuffer* vref); MSGPACK_DLLEXPORT @@ -114,6 +117,9 @@ static inline void msgpack_vrefbuffer_free(msgpack_vrefbuffer* vbuf) static inline int msgpack_vrefbuffer_write(void* data, const char* buf, size_t len) { msgpack_vrefbuffer* vbuf = (msgpack_vrefbuffer*)data; + assert(buf || len == 0); + + if(!buf) return 0; if(len < vbuf->ref_size) { return msgpack_vrefbuffer_append_copy(vbuf, buf, len); @@ -122,7 +128,7 @@ static inline int msgpack_vrefbuffer_write(void* data, const char* buf, size_t l } } -static inline const struct iovec* msgpack_vrefbuffer_vec(const msgpack_vrefbuffer* vref) +static inline const msgpack_iovec* msgpack_vrefbuffer_vec(const msgpack_vrefbuffer* vref) { return vref->array; } diff --git a/src/vendor/msgpack/zbuffer.h b/src/vendor/msgpack/zbuffer.h index 524906fab..c38d627e7 100644 --- a/src/vendor/msgpack/zbuffer.h +++ b/src/vendor/msgpack/zbuffer.h @@ -13,6 +13,7 @@ #include "sysdep.h" #include #include +#include #include #ifdef __cplusplus @@ -121,6 +122,9 @@ static inline int msgpack_zbuffer_write(void* data, const char* buf, size_t len) { msgpack_zbuffer* zbuf = (msgpack_zbuffer*)data; + assert(buf || len == 0); + if(!buf) return 0; + zbuf->stream.next_in = (Bytef*)buf; zbuf->stream.avail_in = (uInt)len; diff --git a/src/vendor/msgpack/zone.h b/src/vendor/msgpack/zone.h index 9005be793..7facd547c 100644 --- a/src/vendor/msgpack/zone.h +++ b/src/vendor/msgpack/zone.h @@ -107,9 +107,9 @@ static inline void* msgpack_zone_malloc(msgpack_zone* zone, size_t size) { char* aligned = (char*)( - (size_t)( + (uintptr_t)( zone->chunk_list.ptr + (MSGPACK_ZONE_ALIGN - 1) - ) / MSGPACK_ZONE_ALIGN * MSGPACK_ZONE_ALIGN + ) & ~(uintptr_t)(MSGPACK_ZONE_ALIGN - 1) ); size_t adjusted_size = size + (size_t)(aligned - zone->chunk_list.ptr); if(zone->chunk_list.free >= adjusted_size) { @@ -120,7 +120,7 @@ static inline void* msgpack_zone_malloc(msgpack_zone* zone, size_t size) { void* ptr = msgpack_zone_malloc_expand(zone, size + (MSGPACK_ZONE_ALIGN - 1)); if (ptr) { - return (char*)((size_t)(ptr) / MSGPACK_ZONE_ALIGN * MSGPACK_ZONE_ALIGN); + return (char*)((uintptr_t)(ptr) & ~(uintptr_t)(MSGPACK_ZONE_ALIGN - 1)); } } return NULL; -- 2.34.1