From 96c9ed391270347c4c7036179fd2815f679ca7cf Mon Sep 17 00:00:00 2001 From: dec05eba Date: Fri, 23 Oct 2020 08:39:15 +0200 Subject: Kill program on read failure or callback returning non-0 value, fix potential crash --- TODO | 3 ++- plugins/Page.hpp | 1 - src/Program.c | 13 +++++++++---- src/QuickMedia.cpp | 8 +++++--- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/TODO b/TODO index d5ab496..5109ec2 100644 --- a/TODO +++ b/TODO @@ -116,4 +116,5 @@ Pressing enter on a pinned message should go to the message in the messages tab. Cache pinned messages on disk (messages by event id), but take into consider edits? for example if one message is pinned in the room and then edited multiple times (such as room rules). In that case cache the pinned message to quickly display it and then fetch the latest version from the server and then replace the message with the latest version. Display file list for nyaa. Remove reply formatting for NOTICE in matrix as well. -Scroll body when adding new items and the selected item fits after the scroll (needed for matrix where we want to see new messages when the last item is not selected). Or show the last item when its not visible in matrix (at the bottom, just like when replying/editing). \ No newline at end of file +Scroll body when adding new items and the selected item fits after the scroll (needed for matrix where we want to see new messages when the last item is not selected). Or show the last item when its not visible in matrix (at the bottom, just like when replying/editing). +Implement our own encryption for matrix. This is also needed to make forwarded message work. Pantalaimon ignores them! \ No newline at end of file diff --git a/plugins/Page.hpp b/plugins/Page.hpp index d8f1d05..2e85cad 100644 --- a/plugins/Page.hpp +++ b/plugins/Page.hpp @@ -35,7 +35,6 @@ namespace QuickMedia { // Mutually exclusive with |is_manga_images_page|, |is_image_board_thread_page| and |is_video_page| virtual bool is_single_page() const { return false; } virtual bool is_trackable() const { return false; } - // Mutually exclusive with |is_manga_images_page|, |is_image_board_thread_page| and |is_video_page| virtual bool is_lazy_fetch_page() const { return false; } // This is called both when first navigating to page and when going back to page diff --git a/src/Program.c b/src/Program.c index fc80e5e..a82bcd2 100644 --- a/src/Program.c +++ b/src/Program.c @@ -74,14 +74,20 @@ int exec_program(const char **args, ProgramOutputCallback output_callback, void int err = errno; fprintf(stderr, "Failed to read from pipe to program %s, error: %s\n", args[0], strerror(err)); result = -err; - goto cleanup; + break; } buffer[bytes_read] = '\0'; - if(output_callback && output_callback(buffer, bytes_read, userdata) != 0) - break; + if(output_callback) { + result = output_callback(buffer, bytes_read, userdata); + if(result != 0) + break; + } } + if(result != 0) + kill(read_program.pid, SIGTERM); + if(waitpid(read_program.pid, &status, 0) == -1) { perror("waitpid failed"); result = -5; @@ -105,7 +111,6 @@ int exec_program(const char **args, ProgramOutputCallback output_callback, void } fprintf(stderr, "), exit status %d\n", exit_status); result = -exit_status; - goto cleanup; } cleanup: diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index 7840326..48d3689 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -1059,9 +1059,11 @@ namespace QuickMedia { } else { page_loop(std::move(new_tabs)); tabs[selected_tab].page->on_navigate_to_page(); - const Json::Value &chapters_json = content_storage_json["chapters"]; - if(chapters_json.isObject()) - json_chapters = &chapters_json; + if(content_storage_json.isObject()) { + const Json::Value &chapters_json = content_storage_json["chapters"]; + if(chapters_json.isObject()) + json_chapters = &chapters_json; + } } } else { // TODO: Show the exact cause of error (get error message from curl). -- cgit v1.2.3