Commit 869093b3 authored by Philip Withnall's avatar Philip Withnall Committed by Olivier Crête

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).
parent e703189b
......@@ -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;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment