tvbuff: add robustness to memory copy related functions

This commit is contained in:
Jaap Keuter 2022-01-16 19:49:48 +00:00 committed by A Wireshark GitLab Utility
parent c8c7479ace
commit 1b46176849
1 changed files with 5 additions and 2 deletions

View File

@ -928,11 +928,11 @@ tvb_memcpy(tvbuff_t *tvb, void *target, const gint offset, size_t length)
DISSECTOR_ASSERT(length <= 0x7FFFFFFF);
check_offset_length(tvb, offset, (gint) length, &abs_offset, &abs_length);
if (tvb->real_data) {
if (target && tvb->real_data) {
return memcpy(target, tvb->real_data + abs_offset, abs_length);
}
if (tvb->ops->tvb_memcpy)
if (target && tvb->ops->tvb_memcpy)
return tvb->ops->tvb_memcpy(tvb, target, abs_offset, abs_length);
/*
@ -975,6 +975,9 @@ tvb_memdup(wmem_allocator_t *scope, tvbuff_t *tvb, const gint offset, size_t len
check_offset_length(tvb, offset, (gint) length, &abs_offset, &abs_length);
if (abs_length == 0)
return NULL;
duped = wmem_alloc(scope, abs_length);
return tvb_memcpy(tvb, duped, abs_offset, abs_length);
}