adding int overflow checks to vrefbuffer

This commit is contained in:
jwang
2018-08-24 15:50:55 -07:00
committed by tbeu
parent 801f61c12c
commit e703d8a2f7

View File

@@ -43,6 +43,10 @@ bool msgpack_vrefbuffer_init(msgpack_vrefbuffer* vbuf,
vbuf->end = array + nfirst;
vbuf->array = array;
if((sizeof(msgpack_vrefbuffer_chunk) + chunk_size) < chunk_size){
return false;
}
chunk = (msgpack_vrefbuffer_chunk*)malloc(
sizeof(msgpack_vrefbuffer_chunk) + chunk_size);
if(chunk == NULL) {
@@ -135,6 +139,9 @@ int msgpack_vrefbuffer_append_copy(msgpack_vrefbuffer* vbuf,
sz = len;
}
if((sizeof(msgpack_vrefbuffer_chunk) + sz) < sz){
return -1;
}
chunk = (msgpack_vrefbuffer_chunk*)malloc(
sizeof(msgpack_vrefbuffer_chunk) + sz);
if(chunk == NULL) {
@@ -165,6 +172,10 @@ int msgpack_vrefbuffer_migrate(msgpack_vrefbuffer* vbuf, msgpack_vrefbuffer* to)
{
size_t sz = vbuf->chunk_size;
if((sizeof(msgpack_vrefbuffer_chunk) + sz) < sz){
return -1;
}
msgpack_vrefbuffer_chunk* empty = (msgpack_vrefbuffer_chunk*)malloc(
sizeof(msgpack_vrefbuffer_chunk) + sz);
if(empty == NULL) {