From a3878a522c98dd8d1060ce20f279419aad83aa25 Mon Sep 17 00:00:00 2001 From: Sebastien Helleu Date: Fri, 20 Oct 2006 09:19:51 +0000 Subject: Fixed crash when loading ruby script if file does not exist, with Ruby >= 1.9 only (bug #18064) --- src/plugins/scripts/lua/weechat-lua.c | 5 ++--- src/plugins/scripts/perl/weechat-perl.c | 15 +++++++++++++-- src/plugins/scripts/python/weechat-python.c | 7 +++---- src/plugins/scripts/ruby/weechat-ruby.c | 13 ++++++++++++- 4 files changed, 30 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/plugins/scripts/lua/weechat-lua.c b/src/plugins/scripts/lua/weechat-lua.c index 2008f649c..950baf90e 100644 --- a/src/plugins/scripts/lua/weechat-lua.c +++ b/src/plugins/scripts/lua/weechat-lua.c @@ -1936,12 +1936,11 @@ weechat_lua_load (t_weechat_plugin *plugin, char *filename) if ((fp = fopen (filename, "r")) == NULL) { - plugin->print_server (plugin, - "Lua error: unable to open file \"%s\"", + plugin->print_server (plugin, "Lua error: script \"%s\" not found", filename); return 0; } - + lua_current_script = NULL; lua_current_interpreter = lua_open (); diff --git a/src/plugins/scripts/perl/weechat-perl.c b/src/plugins/scripts/perl/weechat-perl.c index 21ffaeb07..c89b8c5a7 100644 --- a/src/plugins/scripts/perl/weechat-perl.c +++ b/src/plugins/scripts/perl/weechat-perl.c @@ -34,6 +34,8 @@ #include #include #include +#include +#include #include "../../weechat-plugin.h" #include "../weechat-script.h" @@ -1631,7 +1633,8 @@ weechat_perl_load (t_weechat_plugin *plugin, char *filename) STRLEN len; t_plugin_script tempscript; int eval; - + struct stat buf; + #ifndef MULTIPLICITY char pkgname[64]; #else @@ -1640,8 +1643,16 @@ weechat_perl_load (t_weechat_plugin *plugin, char *filename) #endif plugin->print_server (plugin, "Loading Perl script \"%s\"", filename); - perl_current_script = NULL; + + if (stat (filename, &buf) != 0) + { + plugin->print_server (plugin, "Perl error: script \"%s\" not found", + filename); + return 0; + } + perl_current_script = NULL; + #ifndef MULTIPLICITY snprintf(pkgname, sizeof(pkgname), "%s%d", PKG_NAME_PREFIX, perl_num); perl_num++; diff --git a/src/plugins/scripts/python/weechat-python.c b/src/plugins/scripts/python/weechat-python.c index c8091260d..a894f82b0 100644 --- a/src/plugins/scripts/python/weechat-python.c +++ b/src/plugins/scripts/python/weechat-python.c @@ -1592,14 +1592,13 @@ weechat_python_load (t_weechat_plugin *plugin, char *filename) if ((fp = fopen (filename, "r")) == NULL) { - plugin->print_server (plugin, - "Python error: unable to open file \"%s\"", + plugin->print_server (plugin, "Python error: script \"%s\" not found", filename); return 0; } - + python_current_script = NULL; - + /* PyEval_AcquireLock (); */ python_current_interpreter = Py_NewInterpreter (); PySys_SetArgv(1, argv); diff --git a/src/plugins/scripts/ruby/weechat-ruby.c b/src/plugins/scripts/ruby/weechat-ruby.c index 5001c10d3..4e2cebf90 100644 --- a/src/plugins/scripts/ruby/weechat-ruby.c +++ b/src/plugins/scripts/ruby/weechat-ruby.c @@ -32,6 +32,8 @@ #include #include #include +#include +#include #include "../../weechat-plugin.h" #include "../weechat-script.h" @@ -1796,10 +1798,19 @@ weechat_ruby_load (t_weechat_plugin *plugin, char *filename) char modname[64]; VALUE curModule, ruby_retcode, err; int ruby_error; + struct stat buf; plugin->print_server (plugin, "Loading Ruby script \"%s\"", filename); + + if (stat (filename, &buf) != 0) + { + plugin->print_server (plugin, "Ruby error: script \"%s\" not found", + filename); + return 0; + } + ruby_current_script = NULL; - + snprintf(modname, sizeof(modname), "%s%d", MOD_NAME_PREFIX, ruby_num); ruby_num++; -- cgit v1.2.3