1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-06 08:45:41 +02:00

api: display warning in scripts when invalid pointers (malformed strings) are given to plugin API functions (warning displayed if debug for plugin is >= 1)

This commit is contained in:
Sebastien Helleu
2012-03-24 13:00:50 +01:00
parent 93ec33d491
commit c4cfd651fc
26 changed files with 1014 additions and 912 deletions
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -367,7 +367,7 @@ weechat_guile_load (const char *filename)
char *filename2, *ptr_base_name, *base_name;
SCM module;
if ((weechat_guile_plugin->debug >= 1) || !guile_quiet)
if ((weechat_guile_plugin->debug >= 2) || !guile_quiet)
{
weechat_printf (NULL,
weechat_gettext ("%s: loading script \"%s\""),
@@ -437,7 +437,7 @@ weechat_guile_unload (struct t_plugin_script *script)
{
int *rc;
if ((weechat_guile_plugin->debug >= 1) || !guile_quiet)
if ((weechat_guile_plugin->debug >= 2) || !guile_quiet)
{
weechat_printf (NULL,
weechat_gettext ("%s: unloading script \"%s\""),
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -251,7 +251,7 @@ weechat_lua_load (const char *filename)
return 0;
}
if ((weechat_lua_plugin->debug >= 1) || !lua_quiet)
if ((weechat_lua_plugin->debug >= 2) || !lua_quiet)
{
weechat_printf (NULL,
weechat_gettext ("%s: loading script \"%s\""),
@@ -385,7 +385,7 @@ weechat_lua_unload (struct t_plugin_script *script)
int *rc;
void *interpreter;
if ((weechat_lua_plugin->debug >= 1) || !lua_quiet)
if ((weechat_lua_plugin->debug >= 2) || !lua_quiet)
{
weechat_printf (NULL,
weechat_gettext ("%s: unloading script \"%s\""),
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -390,7 +390,7 @@ weechat_perl_load (const char *filename)
return 0;
}
if ((weechat_perl_plugin->debug >= 1) || !perl_quiet)
if ((weechat_perl_plugin->debug >= 2) || !perl_quiet)
{
weechat_printf (NULL,
weechat_gettext ("%s: loading script \"%s\""),
@@ -557,7 +557,7 @@ weechat_perl_unload (struct t_plugin_script *script)
int *rc;
void *interpreter;
if ((weechat_perl_plugin->debug >= 1) || !perl_quiet)
if ((weechat_perl_plugin->debug >= 2) || !perl_quiet)
{
weechat_printf (NULL,
weechat_gettext ("%s: unloading script \"%s\""),
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -583,7 +583,7 @@ weechat_python_load (const char *filename)
return 0;
}
if ((weechat_python_plugin->debug >= 1) || !python_quiet)
if ((weechat_python_plugin->debug >= 2) || !python_quiet)
{
weechat_printf (NULL,
weechat_gettext ("%s: loading script \"%s\""),
@@ -767,7 +767,7 @@ weechat_python_unload (struct t_plugin_script *script)
void *interpreter;
PyThreadState *old_interpreter;
if ((weechat_python_plugin->debug >= 1) || !python_quiet)
if ((weechat_python_plugin->debug >= 2) || !python_quiet)
{
weechat_printf (NULL,
weechat_gettext ("%s: unloading script \"%s\""),
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -485,7 +485,7 @@ weechat_ruby_load (const char *filename)
return 0;
}
if ((weechat_ruby_plugin->debug >= 1) || !ruby_quiet)
if ((weechat_ruby_plugin->debug >= 2) || !ruby_quiet)
{
weechat_printf (NULL,
weechat_gettext ("%s: loading script \"%s\""),
@@ -621,7 +621,7 @@ weechat_ruby_unload (struct t_plugin_script *script)
int *rc;
void *interpreter;
if ((weechat_ruby_plugin->debug >= 1) || !ruby_quiet)
if ((weechat_ruby_plugin->debug >= 2) || !ruby_quiet)
{
weechat_printf (NULL,
weechat_gettext ("%s: unloading script \"%s\""),
+24 -3
View File
@@ -262,18 +262,39 @@ script_ptr2str (void *pointer)
*/
void *
script_str2ptr (const char *pointer_str)
script_str2ptr (struct t_weechat_plugin *weechat_plugin,
const char *script_name, const char *function_name,
const char *str_pointer)
{
long unsigned int value;
int rc;
struct t_gui_buffer *ptr_buffer;
if (!pointer_str || (pointer_str[0] != '0') || (pointer_str[1] != 'x'))
if (!str_pointer || !str_pointer[0])
return NULL;
rc = sscanf (pointer_str + 2, "%lx", &value);
if ((str_pointer[0] != '0') || (str_pointer[1] != 'x'))
goto invalid;
rc = sscanf (str_pointer + 2, "%lx", &value);
if ((rc != EOF) && (rc >= 1))
return (void *)value;
invalid:
if (weechat_plugin->debug >= 1)
{
ptr_buffer = weechat_buffer_search_main ();
if (ptr_buffer)
{
weechat_buffer_set (ptr_buffer, "print_hooks_enabled", "0");
weechat_printf (NULL,
_("%s%s: warning, invalid pointer (\"%s\") for "
"function \"%s\" (script: %s)"),
weechat_prefix ("error"), weechat_plugin->name,
str_pointer, function_name, script_name);
weechat_buffer_set (ptr_buffer, "print_hooks_enabled", "1");
}
}
return NULL;
}
+3 -1
View File
@@ -97,7 +97,9 @@ extern void script_init (struct t_weechat_plugin *weechat_plugin,
extern int script_valid (struct t_plugin_script *scripts,
struct t_plugin_script *script);
extern char *script_ptr2str (void *pointer);
extern void *script_str2ptr (const char *pointer_str);
extern void *script_str2ptr (struct t_weechat_plugin *weechat_plugin,
const char *script_name, const char *function_name,
const char *pointer_str);
extern void script_auto_load (struct t_weechat_plugin *weechat_plugin,
void (*callback)(void *data, const char *filename));
extern struct t_plugin_script *script_search (struct t_weechat_plugin *weechat_plugin,
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -290,7 +290,7 @@ weechat_tcl_load (const char *filename)
return 0;
}
if ((weechat_tcl_plugin->debug >= 1) || !tcl_quiet)
if ((weechat_tcl_plugin->debug >= 2) || !tcl_quiet)
{
weechat_printf (NULL,
weechat_gettext ("%s: loading script \"%s\""),
@@ -369,7 +369,7 @@ weechat_tcl_unload (struct t_plugin_script *script)
Tcl_Interp* interp;
int *rc;
if ((weechat_tcl_plugin->debug >= 1) || !tcl_quiet)
if ((weechat_tcl_plugin->debug >= 2) || !tcl_quiet)
{
weechat_printf (NULL,
weechat_gettext ("%s: unloading script \"%s\""),