vlc/vlc-2.0 | branch: master | Pierre Ynard <[email protected]> | Wed May 23 
05:07:19 2012 +0200| [1c9c442340555cb165471ebbbe79285a038a8aa6] | committer: 
Jean-Baptiste Kempf

lua: fix more sd input options and lua stack use-after-gc

Strings from the lua stack stop being valid after you pop them
(cherry picked from commit 8f048e9cabebeec8b514e981993d16acfbbd7c28)

Signed-off-by: Jean-Baptiste Kempf <[email protected]>

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

 modules/lua/libs/sd.c |   25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)

diff --git a/modules/lua/libs/sd.c b/modules/lua/libs/sd.c
index 9c87cdf..143c177 100644
--- a/modules/lua/libs/sd.c
+++ b/modules/lua/libs/sd.c
@@ -224,19 +224,23 @@ static int vlclua_sd_add_item( lua_State *L )
         lua_getfield( L, -1, "path" );
         if( lua_isstring( L, -1 ) )
         {
-            char **ppsz_options = NULL;
-            int i_options = 0;
             const char *psz_path = lua_tostring( L, -1 );
 
-            lua_pop( L, 1 );
-            vlclua_read_options( p_sd, L, &i_options, &ppsz_options );
-            lua_getfield( L, -1, "title" );
+            lua_getfield( L, -2, "title" );
             const char *psz_title = luaL_checkstring( L, -1 ) ? 
luaL_checkstring( L, -1 ) : psz_path;
+
+            /* The table must be at the top of the stack when calling
+             * vlclua_read_options() */
+            char **ppsz_options = NULL;
+            int i_options = 0;
+            lua_pushvalue( L, -3 );
+            vlclua_read_options( p_sd, L, &i_options, &ppsz_options );
+
             input_item_t *p_input = input_item_NewExt( psz_path, psz_title,
                                                        i_options,
                                                        (const char 
**)ppsz_options,
                                                        
VLC_INPUT_OPTION_TRUSTED, -1 );
-            lua_pop( L, 1 );
+            lua_pop( L, 3 );
 
             if( p_input )
             {
@@ -307,16 +311,21 @@ static int vlclua_node_add_subitem( lua_State *L )
             lua_getfield( L, -1, "path" );
             if( lua_isstring( L, -1 ) )
             {
+                const char *psz_path = lua_tostring( L, -1 );
+
+                /* The table must be at the top of the stack when calling
+                 * vlclua_read_options() */
                 char **ppsz_options = NULL;
                 int i_options = 0;
-                const char *psz_path = lua_tostring( L, -1 );
+                lua_pushvalue( L, -2 );
                 vlclua_read_options( p_sd, L, &i_options, &ppsz_options );
+
                 input_item_node_t *p_input_node = input_item_node_Create( 
*pp_node );
                 input_item_t *p_input = input_item_NewExt( psz_path,
                                                            psz_path, i_options,
                                                            (const char 
**)ppsz_options,
                                                            
VLC_INPUT_OPTION_TRUSTED, -1 );
-                lua_pop( L, 1 );
+                lua_pop( L, 2 );
 
                 if( p_input )
                 {

_______________________________________________
vlc-commits mailing list
[email protected]
http://mailman.videolan.org/listinfo/vlc-commits

Reply via email to