diff options
author | Philip Withnall <philip.withnall@collabora.co.uk> | 2013-12-17 09:54:01 +0000 |
---|---|---|
committer | Olivier Crête <olivier.crete@collabora.com> | 2013-12-18 17:50:58 -0500 |
commit | 869093b34758646d915ef06a2473aa0b2c7432d1 (patch) | |
tree | 8f3f69d03d94273ab3df591103582a9be741e7d0 /stun | |
parent | e703189bfd724da1860a730af2b4252dac310b93 (diff) |
stun: Explicitly avoid a memcpy() from NULL
If stun_message_append_bytes() is called through
stun_message_append_flag(), data will be NULL and len will be 0. This
will result in a memcpy(ptr, NULL, 0) call. This probably won’t do any
harm (since any reasonable memcpy() implementation will immediately
return if (len == 0)), but the standard allows for memcpy() to explode
if (data == NULL), regardless of the value of len.
In order to be conformant, and to shut up the scan-build static analysis
warning about it, only do the memcpy() if (len > 0).
Diffstat (limited to 'stun')
-rw-r--r-- | stun/stunmessage.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/stun/stunmessage.c b/stun/stunmessage.c index e9a831c..874d3f1 100644 --- a/stun/stunmessage.c +++ b/stun/stunmessage.c @@ -377,7 +377,9 @@ stun_message_append_bytes (StunMessage *msg, StunAttribute type, if (ptr == NULL) return STUN_MESSAGE_RETURN_NOT_ENOUGH_SPACE; - memcpy (ptr, data, len); + if (len > 0) + memcpy (ptr, data, len); + return STUN_MESSAGE_RETURN_SUCCESS; } |