diff mbox

[FFmpeg-devel,1/5] avutil/encryption_info: Don't pass NULL to memcpy

Message ID 20190916155502.17579-1-andreas.rheinhardt@gmail.com
State Superseded
Headers show

Commit Message

Andreas Rheinhardt Sept. 16, 2019, 3:54 p.m. UTC
The pointer arguments to memcpy (and several other functions of the
C standard library) are not allowed to be NULL, not even when the number
of bytes to copy is zero. An AVEncryptionInitInfo's data pointer is
explicitly allowed to be NULL and yet av_encryption_init_info_add_side_data
uncoditionally used it as a source pointer to copy from. This commit changes
this so that copying is only done if the number of bytes to copy is > 0.

Fixes ticket #8141 as well as a part of ticket #8150.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
 libavutil/encryption_info.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff mbox


diff --git a/libavutil/encryption_info.c b/libavutil/encryption_info.c
index 812c704776..614791f2af 100644
--- a/libavutil/encryption_info.c
+++ b/libavutil/encryption_info.c
@@ -331,7 +331,8 @@  uint8_t *av_encryption_init_info_add_side_data(const AVEncryptionInitInfo *info,
             memcpy(cur_buffer, cur_info->key_ids[i], cur_info->key_id_size);
             cur_buffer += cur_info->key_id_size;
-        memcpy(cur_buffer, cur_info->data, cur_info->data_size);
+        if (cur_info->data_size > 0)
+            memcpy(cur_buffer, cur_info->data, cur_info->data_size);
         cur_buffer += cur_info->data_size;