mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-06-25 22:15:23 +02:00
adding unit tests and fixing same overflow issue in hpp files
This commit is contained in:
parent
b3dfe28be4
commit
60930f4b12
@ -71,6 +71,12 @@ public:
|
|||||||
m_end = array + nfirst;
|
m_end = array + nfirst;
|
||||||
m_array = array;
|
m_array = array;
|
||||||
|
|
||||||
|
|
||||||
|
if((sizeof(chunk) + chunk_size) < chunk_size){
|
||||||
|
throw std::bad_alloc();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
chunk* c = static_cast<chunk*>(::malloc(sizeof(chunk) + chunk_size));
|
chunk* c = static_cast<chunk*>(::malloc(sizeof(chunk) + chunk_size));
|
||||||
if(!c) {
|
if(!c) {
|
||||||
::free(array);
|
::free(array);
|
||||||
@ -141,7 +147,11 @@ public:
|
|||||||
if(sz < len) {
|
if(sz < len) {
|
||||||
sz = len;
|
sz = len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(sizeof(chunk) + sz < sz){
|
||||||
|
throw std::bad_alloc();
|
||||||
|
}
|
||||||
|
|
||||||
chunk* c = static_cast<chunk*>(::malloc(sizeof(chunk) + sz));
|
chunk* c = static_cast<chunk*>(::malloc(sizeof(chunk) + sz));
|
||||||
if(!c) {
|
if(!c) {
|
||||||
throw std::bad_alloc();
|
throw std::bad_alloc();
|
||||||
@ -183,6 +193,10 @@ public:
|
|||||||
{
|
{
|
||||||
size_t sz = m_chunk_size;
|
size_t sz = m_chunk_size;
|
||||||
|
|
||||||
|
if((sizeof(chunk) + sz) < sz){
|
||||||
|
throw std::bad_alloc();
|
||||||
|
}
|
||||||
|
|
||||||
chunk* empty = static_cast<chunk*>(::malloc(sizeof(chunk) + sz));
|
chunk* empty = static_cast<chunk*>(::malloc(sizeof(chunk) + sz));
|
||||||
if(!empty) {
|
if(!empty) {
|
||||||
throw std::bad_alloc();
|
throw std::bad_alloc();
|
||||||
|
@ -1352,3 +1352,16 @@ TEST(MSGPACKC, unpack_array_uint64)
|
|||||||
EXPECT_EQ(0xFFF0000000000001LL, obj.via.array.ptr[0].via.u64);
|
EXPECT_EQ(0xFFF0000000000001LL, obj.via.array.ptr[0].via.u64);
|
||||||
msgpack_zone_destroy(&z);
|
msgpack_zone_destroy(&z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TEST(MSGPACKC, vreff_buffer_overflow)
|
||||||
|
{
|
||||||
|
msgpack_vrefbuffer vbuf;
|
||||||
|
msgpack_vrefbuffer to;
|
||||||
|
size_t ref_size = 0;
|
||||||
|
size_t len = 0x1000;
|
||||||
|
size_t chunk_size = std::numeric_limits<size_t>::max();
|
||||||
|
char *buf = (char *)malloc(len);
|
||||||
|
EXPECT_FALSE(msgpack_vrefbuffer_init(&vbuf, ref_size, chunk_size));
|
||||||
|
EXPECT_EQ(-1, msgpack_vrefbuffer_migrate(&vbuf, &to));
|
||||||
|
}
|
||||||
|
@ -264,3 +264,12 @@ TEST(MSGPACK, vrefbuffer_small_int64)
|
|||||||
msgpack::vrefbuffer vbuf(0, 0);
|
msgpack::vrefbuffer vbuf(0, 0);
|
||||||
GEN_TEST_VREF(int64_t, vbuf);
|
GEN_TEST_VREF(int64_t, vbuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(MSGPACK, vref_buffer_overflow)
|
||||||
|
{
|
||||||
|
size_t chunk_size = std::numeric_limits<size_t>::max();
|
||||||
|
char *buf = (char *)malloc(chunk_size);
|
||||||
|
ASSERT_THROW(msgpack::vrefbuffer vbuf(0, chunk_size), std::bad_alloc);
|
||||||
|
msgpack::vrefbuffer vbuf(0,0x1000);
|
||||||
|
ASSERT_THROW(vbuf.append_copy(buf, chunk_size), std::bad_alloc);
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user