Merge pull request #890 from ygj6/c_master

check null pointer before using memcpy()
This commit is contained in:
Takatoshi Kondo 2020-07-01 18:25:08 +09:00 committed by GitHub
commit 3bb121fb8f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -12,6 +12,7 @@
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#ifdef __cplusplus
extern "C" {
@ -59,6 +60,7 @@ static inline void msgpack_sbuffer_free(msgpack_sbuffer* sbuf)
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(sbuf->alloc - sbuf->size < len) {
void* tmp;
@ -81,8 +83,10 @@ static inline int msgpack_sbuffer_write(void* data, const char* buf, size_t len)
sbuf->alloc = nsize;
}
if(buf) {
memcpy(sbuf->data + sbuf->size, buf, len);
sbuf->size += len;
}
return 0;
}