Don't assert out on tvb_memcpy() with a null data pointer if the length is 0.

If the length is 0, there's nothing to copy, so it doesn't matter if
there's no data to copy from.  This fixes problems caused by allocating
a zero-length buffer and using that as the data for a tvbuff; the
allocation returns null, so the data pointer is null.

Change-Id: I8037ae4b96d30e90a716852bb7e22d3980444f83
Reviewed-on: https://code.wireshark.org/review/3761
Reviewed-by: Guy Harris <guy@alum.mit.edu>
This commit is contained in:
Guy Harris 2014-08-21 00:35:38 -07:00
parent bed29af46d
commit 66318ad5eb
1 changed files with 11 additions and 3 deletions

View File

@ -795,9 +795,17 @@ tvb_memcpy(tvbuff_t *tvb, void *target, const gint offset, size_t length)
if (tvb->ops->tvb_memcpy)
return tvb->ops->tvb_memcpy(tvb, target, abs_offset, abs_length);
/* XXX, fallback to slower method */
DISSECTOR_ASSERT_NOT_REACHED();
/*
* If the length is 0, there's nothing to do.
* (tvb->real_data could be null if it's allocated with
* a size of length.)
*/
if (length != 0) {
/*
* XXX, fallback to slower method
*/
DISSECTOR_ASSERT_NOT_REACHED();
}
return NULL;
}