logo

badwolf

minimalist and privacy-oriented web browser based on WebKitGTK git clone https://hacktivis.me/git/badwolf.git
commit: 7ab0cd492adee10f2d88f5c978c3ff5a0acbdfef
parent 7f4b6c84006c4af9d34319f5f29d890935580370
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Fri, 17 Mar 2023 08:09:44 +0100

userscripts: Handle g_file_get_contents errors

Diffstat:

Mpo/messages.pot10+++++++---
Muserscripts.c31+++++++++++++++++++------------
2 files changed, 26 insertions(+), 15 deletions(-)

diff --git a/po/messages.pot b/po/messages.pot @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: Badwolf 1.2.0+geb77866.develop\n" "Report-Msgid-Bugs-To: contact+badwolf-msgid@hacktivis.me\n" -"POT-Creation-Date: 2023-03-17 03:08+0100\n" +"POT-Creation-Date: 2023-03-17 08:08+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Language-Team: LANGUAGE <LL@li.org>\n" @@ -149,11 +149,15 @@ msgid "badwolf: Checking for userscripts matching %s\n" msgstr "" #, c-format -msgid "badwolf: Failed to load userscripts: Out of Memory\n" +msgid "badwolf: Error getting userscript content: %s\n" msgstr "" #, c-format -msgid "badwolf: Failed to load userscripts: Read Error\n" +msgid "badwolf: Failed to list userscripts: Out of Memory\n" +msgstr "" + +#, c-format +msgid "badwolf: Failed to list userscripts: Read Error\n" msgstr "" #, c-format diff --git a/userscripts.c b/userscripts.c @@ -29,28 +29,35 @@ load_userscripts(WebKitUserContentManager *content_manager) goto clean; break; case GLOB_NOSPACE: - fprintf(stderr, _("badwolf: Failed to load userscripts: Out of Memory\n")); + fprintf(stderr, _("badwolf: Failed to list userscripts: Out of Memory\n")); goto clean; break; case GLOB_ABORTED: - fprintf(stderr, _("badwolf: Failed to load userscripts: Read Error\n")); + fprintf(stderr, _("badwolf: Failed to list userscripts: Read Error\n")); goto clean; break; } for(size_t i = 0; i < scripts_path_glob.gl_pathc; i++) { - gsize l = 0; gchar *contents; - g_file_get_contents(scripts_path_glob.gl_pathv[i], &contents, &l, NULL); - - WebKitUserScript *userscript = - webkit_user_script_new(contents, - WEBKIT_USER_CONTENT_INJECT_ALL_FRAMES, - WEBKIT_USER_SCRIPT_INJECT_AT_DOCUMENT_START, - NULL, - NULL); - webkit_user_content_manager_add_script(content_manager, userscript); + GError *err = NULL; + if(g_file_get_contents(scripts_path_glob.gl_pathv[i], &contents, NULL, &err) && err == NULL) + { + + WebKitUserScript *userscript = + webkit_user_script_new(contents, + WEBKIT_USER_CONTENT_INJECT_ALL_FRAMES, + WEBKIT_USER_SCRIPT_INJECT_AT_DOCUMENT_START, + NULL, + NULL); + webkit_user_content_manager_add_script(content_manager, userscript); + } + else + { + fprintf(stderr, _("badwolf: Error getting userscript content: %s\n"), err->message); + g_error_free(err); + } } fprintf(stderr, _("badwolf: Notice: Userscripts loaded\n"));