From e7c37d79e67c687e808dc4704f1a81deb7856702 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Mon, 24 Aug 2020 06:51:57 +0900 Subject: [PATCH] Fix segmentation fault on file open errors --- Makefile.am | 2 ++ Makefile.in | 2 ++ main.c | 3 +++ 3 files changed, 7 insertions(+) diff --git a/Makefile.am b/Makefile.am index 6439cf9..9c0df2e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -16,6 +16,8 @@ seq2gif_CFLAGS = $(MAYBE_COVERAGE) test: all ./seq2gif -i tests/data/sl.tty -o /dev/null + ! ./seq2gif -i /non-existent-file.tty -o /dev/null + ! ./seq2gif -i tests/data/sl.tty -o /non-existent-file.out coveralls: test coveralls -E '.*\.h' -e tests -e glyph -e m4 diff --git a/Makefile.in b/Makefile.in index 85625a7..9f58958 100644 --- a/Makefile.in +++ b/Makefile.in @@ -906,6 +906,8 @@ uninstall-am: uninstall-binPROGRAMS test: all ./seq2gif -i tests/data/sl.tty -o /dev/null + ! ./seq2gif -i /non-existent-file.tty -o /dev/null + ! ./seq2gif -i tests/data/sl.tty -o /non-existent-file.out coveralls: test coveralls -E '.*\.h' -e tests -e glyph -e m4 diff --git a/main.c b/main.c index 91474c0..ae3f7d6 100644 --- a/main.c +++ b/main.c @@ -565,6 +565,9 @@ int main(int argc, char *argv[]) in_file = open_input_file(settings.input); out_file = open_output_file(settings.output); + if (in_file == NULL || out_file == NULL) { + exit(1); + } maxlen = 2048; obuf = malloc(maxlen);