[vlc-commits] vlcshell: use checked allocs in ExecuteScheduleProperty

Francois Cartegnie git at videolan.org
Wed Jul 20 16:25:03 CEST 2016


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Wed Jul 20 11:13:19 2016 +0200| [a08a8509b911a4218f9f0827af9e9a82975f0e7a] | committer: Francois Cartegnie

vlcshell: use checked allocs in ExecuteScheduleProperty

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

 src/input/vlmshell.c |   32 +++++++++++++++++++++++---------
 1 file changed, 23 insertions(+), 9 deletions(-)

diff --git a/src/input/vlmshell.c b/src/input/vlmshell.c
index d3aefe1..4b35119 100644
--- a/src/input/vlmshell.c
+++ b/src/input/vlmshell.c
@@ -583,26 +583,40 @@ static int ExecuteScheduleProperty( vlm_t *p_vlm, vlm_schedule_sys_t *p_schedule
         }
         else if( !strcmp( ppsz_property[i], "append" ) )
         {
-            char *psz_line;
-            int j;
+            char *psz_line, *psz_realloc;
+            int j, i_ret = VLC_SUCCESS;
             /* Beware: everything behind append is considered as
              * command line */
 
             if( ++i >= i_property )
                 break;
 
-            psz_line = xstrdup( ppsz_property[i] );
+            psz_line = strdup( ppsz_property[i] );
+            if( unlikely(psz_line == NULL) )
+                goto error;
+
             for( j = i+1; j < i_property; j++ )
             {
-                psz_line = xrealloc( psz_line,
-                        strlen(psz_line) + strlen(ppsz_property[j]) + 1 + 1 );
-                strcat( psz_line, " " );
-                strcat( psz_line, ppsz_property[j] );
+                psz_realloc = realloc( psz_line,
+                                       strlen(psz_line) + strlen(ppsz_property[j]) + 1 + 1 );
+                if( likely(psz_realloc) )
+                {
+                    psz_line = psz_realloc;
+                    strcat( psz_line, " " );
+                    strcat( psz_line, ppsz_property[j] );
+                }
+                else
+                {
+                    i_ret = VLC_ENOMEM;
+                    break;
+                }
             }
 
-            int val = vlm_ScheduleSetup( p_schedule, "append", psz_line );
+            if( i_ret == VLC_SUCCESS )
+                i_ret = vlm_ScheduleSetup( p_schedule, "append", psz_line );
             free( psz_line );
-            if( val )
+
+            if( i_ret )
                 goto error;
             break;
         }



More information about the vlc-commits mailing list