]> git.sesse.net Git - vlc/commitdiff
Lua: check variable type before adding a callback
authorJean-Philippe André <jpeg@endymion.via.ecp.fr>
Tue, 10 Nov 2009 17:19:01 +0000 (18:19 +0100)
committerJean-Philippe André <jpeg@endymion.via.ecp.fr>
Wed, 11 Nov 2009 21:12:55 +0000 (22:12 +0100)
modules/misc/lua/libs/variables.c

index ad5c4717c0c0e96bf62491743fb2e6c3bb15daf4..c5ec5cdbd981397d88ac2e6f0b794ce2fd0c1380 100644 (file)
@@ -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 ) );