[vlc-commits] rtp: fix stringop-truncation warning

Alexandre Janniaux git at videolan.org
Mon Oct 7 09:48:10 CEST 2019


vlc | branch: master | Alexandre Janniaux <ajanni at videolabs.io> | Thu Sep  5 19:43:46 2019 +0200| [a5c07a7c2cfe11950b52197651f127d07f7d2ef4] | committer: Thomas Guillem

rtp: fix stringop-truncation warning

strncpy inserts a last null character, which prevents from copying 8
bytes correctly. Instead, zero the integer and reproduce strncpy
behaviour without the trailing \0.

Signed-off-by: Thomas Guillem <thomas at gllm.fr>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=a5c07a7c2cfe11950b52197651f127d07f7d2ef4
---

 modules/stream_out/rtp.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/modules/stream_out/rtp.c b/modules/stream_out/rtp.c
index 3341bde9c5..d4c7460477 100644
--- a/modules/stream_out/rtp.c
+++ b/modules/stream_out/rtp.c
@@ -1560,9 +1560,11 @@ static vlc_tick_t rtp_init_ts( const vod_media_t *p_media,
     if (p_media == NULL || psz_vod_session == NULL)
         return vlc_tick_now();
 
-    uint64_t i_ts_init;
+    uint64_t i_ts_init = 0;
     /* As per RFC 2326, session identifiers are at least 8 bytes long */
-    strncpy((char *)&i_ts_init, psz_vod_session, sizeof(uint64_t));
+    size_t session_length = strlen(psz_vod_session);
+    memcpy(&i_ts_init, psz_vod_session, __MIN(session_length,
+                                              sizeof(uint64_t)));
     i_ts_init ^= (uintptr_t)p_media;
     /* Limit the timestamp to 48 bits, this is enough and allows us
      * to stay away from overflows */



More information about the vlc-commits mailing list