[vlc-commits] mp4: use strndup() where applicable

Rémi Denis-Courmont git at videolan.org
Sat May 5 19:23:05 CEST 2012


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat May  5 20:21:42 2012 +0300| [45296a172c03e99b7e1d7cfdd2d5aed105ceaed0] | committer: Rémi Denis-Courmont

mp4: use strndup() where applicable

As a side note, this fixes a valgrind heap read overflow, but I do not
see why. I suspect a conflict between valgrind and some optimization in
libc or gcc here.

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

 modules/demux/mp4/libmp4.c |    8 +++-----
 1 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/modules/demux/mp4/libmp4.c b/modules/demux/mp4/libmp4.c
index 2d478c6..ec734a6 100644
--- a/modules/demux/mp4/libmp4.c
+++ b/modules/demux/mp4/libmp4.c
@@ -3609,11 +3609,9 @@ static void get_token( char **ppsz_path, char **ppsz_token, int *pi_number )
     {
         i_len = 1;
     }
-    *ppsz_token = xmalloc( i_len + 1 );
-
-    memcpy( *ppsz_token, *ppsz_path, i_len );
-
-    (*ppsz_token)[i_len] = '\0';
+    *ppsz_token = strndup( *ppsz_path, i_len );
+    if( unlikely(!*ppsz_token) )
+        abort();
 
     *ppsz_path += i_len;
 



More information about the vlc-commits mailing list