Skip to content

Commit 90677eb

Browse files
committed
Fix UB in v4raw_ref::operator==
Behaviour of memcmp is undefined if any of pointers passed to it is null. See https://en.cppreference.com/w/c/string/byte/memcmp for details. UB was detected on test MSGPACK_V4RAW_REF.pack_unpack_fix_l with UB-sanitizer.
1 parent dfbfd92 commit 90677eb

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

include/msgpack/v1/adaptor/v4raw.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ struct v4raw_ref {
3333

3434
bool operator== (const v4raw_ref& x) const
3535
{
36-
return size == x.size && std::memcmp(ptr, x.ptr, size) == 0;
36+
return size == x.size && (size == 0 || std::memcmp(ptr, x.ptr, size) == 0);
3737
}
3838

3939
bool operator!= (const v4raw_ref& x) const

0 commit comments

Comments
 (0)