summaryrefslogtreecommitdiff
path: root/stun
diff options
context:
space:
mode:
authorPhilip Withnall <philip.withnall@collabora.co.uk>2013-12-17 09:54:01 +0000
committerOlivier Crête <olivier.crete@collabora.com>2013-12-18 17:50:58 -0500
commit869093b34758646d915ef06a2473aa0b2c7432d1 (patch)
tree8f3f69d03d94273ab3df591103582a9be741e7d0 /stun
parente703189bfd724da1860a730af2b4252dac310b93 (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.c4
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;
}