From 003f15507da6a1dfe2352a23240cffc8ab34be24 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Tue, 12 Jul 2016 13:06:15 +0200 Subject: [PATCH 1/2] Allow CWD-relative paths with /script load Replace the usage of printfs with glib functions to build the paths. --- src/perl/perl-core.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/perl/perl-core.c b/src/perl/perl-core.c index cb690906..69d07394 100644 --- a/src/perl/perl-core.c +++ b/src/perl/perl-core.c @@ -354,10 +354,11 @@ PERL_SCRIPT_REC *perl_script_find_package(const char *package) /* Returns full path for the script */ char *perl_script_get_path(const char *name) { - struct stat statbuf; char *file, *path; - if (g_path_is_absolute(name) || (name[0] == '~' && name[1] == '/')) { + if (g_path_is_absolute(name) || + (name[0] == '~' && name[1] == '/') || + (name[0] == '.' && name[1] == G_DIR_SEPARATOR)) { /* full path specified */ return convert_home(name); } @@ -366,19 +367,25 @@ char *perl_script_get_path(const char *name) file = IS_PERL_SCRIPT(name) ? g_strdup(name) : g_strdup_printf("%s.pl", name); - /* check from ~/.irssi/scripts/ */ - path = g_strdup_printf("%s/scripts/%s", get_irssi_dir(), file); - if (stat(path, &statbuf) != 0) { - /* check from SCRIPTDIR */ - g_free(path); - path = g_strdup_printf(SCRIPTDIR"/%s", file); - if (stat(path, &statbuf) != 0) { - g_free(path); - path = NULL; - } + /* check in ~/.irssi/scripts/ */ + path = g_build_filename(get_irssi_dir(), "scripts", file, NULL); + if (g_file_test(path, G_FILE_TEST_IS_REGULAR)) { + g_free(file); + return path; } + g_free(path); + + /* check in SCRIPTDIR */ + path = g_build_filename(SCRIPTDIR, file, NULL); + if (g_file_test(path, G_FILE_TEST_IS_REGULAR)) { + g_free(file); + return path; + } + g_free(path); + g_free(file); - return path; + + return NULL; } /* If core should handle printing script errors */ From b87c7b31d5cdcc43841312d5414548d7c4fdfb10 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Tue, 12 Jul 2016 13:32:08 +0200 Subject: [PATCH 2/2] Make sure the path given to perl_script_load_file is a file. --- src/perl/perl-core.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/perl/perl-core.c b/src/perl/perl-core.c index 69d07394..f47b3bc5 100644 --- a/src/perl/perl-core.c +++ b/src/perl/perl-core.c @@ -293,6 +293,9 @@ PERL_SCRIPT_REC *perl_script_load_file(const char *path) g_return_val_if_fail(path != NULL, NULL); + if (g_file_test(path, G_FILE_TEST_IS_REGULAR) == FALSE) + return NULL; + name = script_file_get_name(path); return script_load(name, path, NULL); }