From 12db568b03767f6bc90165364e6dde210995c367 Mon Sep 17 00:00:00 2001 From: Manoj Ampalam Date: Sun, 16 Oct 2016 15:19:26 -0700 Subject: [PATCH] fdopen fix in keygen utility --- ssh-keygen.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ssh-keygen.c b/ssh-keygen.c index d5f1ef1..8247b33 100644 --- a/ssh-keygen.c +++ b/ssh-keygen.c @@ -990,6 +990,11 @@ do_gen_all_hostkeys(struct passwd *pw) } sshkey_free(private); strlcat(identity_file, ".pub", sizeof(identity_file)); +#ifdef WINDOWS + if ((f = fopen(identity_file, "w")) == NULL) { + error("fopen %s failed: %s", identity_file, strerror(errno)); + /* TODO - set permissions on file */ +#else fd = open(identity_file, O_WRONLY | O_CREAT | O_TRUNC, 0644); if (fd == -1) { error("Could not save your public key in %s", @@ -999,9 +1004,11 @@ do_gen_all_hostkeys(struct passwd *pw) continue; } f = fdopen(fd, "w"); + if (f == NULL) { error("fdopen %s failed", identity_file); close(fd); +#endif sshkey_free(public); first = 0; continue; @@ -2765,10 +2772,10 @@ passphrase_again: printf("Your identification has been saved in %s.\n", identity_file); strlcat(identity_file, ".pub", sizeof(identity_file)); - /* TODO - for windows call fopen directly*/ #ifdef WINDOWS if ((f = fopen(identity_file, "w")) == NULL) fatal("fopen %s failed: %s", identity_file, strerror(errno)); + /* TODO - set permissions on file */ #else if ((fd = open(identity_file, O_WRONLY|O_CREAT|O_TRUNC, 0644)) == -1) fatal("Unable to save public key to %s: %s",