cmdgen: fix segfault on failing to open the output file.

D'oh - simply forgot to check the return value of fopen for NULL.
This commit is contained in:
Simon Tatham 2018-10-15 22:26:20 +01:00
Родитель 35a4283615
Коммит b9bfc81531
1 изменённых файлов: 14 добавлений и 4 удалений

Просмотреть файл

@ -959,10 +959,15 @@ int main(int argc, char **argv)
{ {
FILE *fp; FILE *fp;
if (outfile) if (outfile) {
fp = f_open(outfilename, "w", FALSE); fp = f_open(outfilename, "w", FALSE);
else if (!fp) {
fprintf(stderr, "unable to open output file\n");
exit(1);
}
} else {
fp = stdout; fp = stdout;
}
if (sshver == 1) { if (sshver == 1) {
ssh1_write_pubkey(fp, ssh1key); 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); fp = f_open(outfilename, "w", FALSE);
else if (!fp) {
fprintf(stderr, "unable to open output file\n");
exit(1);
}
} else {
fp = stdout; fp = stdout;
}
fprintf(fp, "%s\n", fingerprint); fprintf(fp, "%s\n", fingerprint);
if (outfile) if (outfile)
fclose(fp); fclose(fp);