From b9bfc81531a897e0160f3914152eca6be4307c3e Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Mon, 15 Oct 2018 22:26:20 +0100 Subject: [PATCH] cmdgen: fix segfault on failing to open the output file. D'oh - simply forgot to check the return value of fopen for NULL. --- cmdgen.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/cmdgen.c b/cmdgen.c index a08e7de9..5216e753 100644 --- a/cmdgen.c +++ b/cmdgen.c @@ -959,10 +959,15 @@ int main(int argc, char **argv) { FILE *fp; - if (outfile) + if (outfile) { fp = f_open(outfilename, "w", FALSE); - else + if (!fp) { + fprintf(stderr, "unable to open output file\n"); + exit(1); + } + } else { fp = stdout; + } if (sshver == 1) { ssh1_write_pubkey(fp, ssh1key); @@ -1003,10 +1008,15 @@ int main(int argc, char **argv) } } - if (outfile) + if (outfile) { fp = f_open(outfilename, "w", FALSE); - else + if (!fp) { + fprintf(stderr, "unable to open output file\n"); + exit(1); + } + } else { fp = stdout; + } fprintf(fp, "%s\n", fingerprint); if (outfile) fclose(fp);