[vlc-devel] commit: Lua: check variable type before adding a callback ( Jean-Philippe André )

git version control git at videolan.org
Wed Nov 11 22:17:21 CET 2009


vlc | branch: master | Jean-Philippe André <jpeg at endymion.via.ecp.fr> | Tue Nov 10 18:19:01 2009 +0100| [9c1cb680d5ec3f35624a8d4e238eead0830c5a66] | committer: Jean-Philippe André 

Lua: check variable type before adding a callback

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

 modules/misc/lua/libs/variables.c |   21 +++++++++++++++++++++
 1 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/modules/misc/lua/libs/variables.c b/modules/misc/lua/libs/variables.c
index ad5c471..c5ec5cd 100644
--- a/modules/misc/lua/libs/variables.c
+++ b/modules/misc/lua/libs/variables.c
@@ -342,6 +342,27 @@ static int vlclua_add_callback( lua_State *L )
     lua_settop( L, 4 ); /* makes sure that optional data arg is set */
     if( !lua_isfunction( L, 3 ) )
         return vlclua_error( L );
+
+    if( !pp_obj || !*pp_obj )
+        return vlclua_error( L );
+
+    /* Check variable type, in order to avoid PANIC */
+    switch( var_Type( *pp_obj, psz_var ) )
+    {
+        case VLC_VAR_BOOL:
+        case VLC_VAR_INTEGER:
+        case VLC_VAR_STRING:
+        case VLC_VAR_FLOAT:
+        case VLC_VAR_TIME:
+            break;
+        case VLC_VAR_ADDRESS:
+        case VLC_VAR_VOID:
+        case VLC_VAR_MUTEX:
+        case VLC_VAR_LIST:
+        default:
+            return vlclua_error( L );
+    }
+
     i_index++;
 
     p_callback = (vlclua_callback_t*)malloc( sizeof( vlclua_callback_t ) );




More information about the vlc-devel mailing list