Skip to content

Commit 12db568

Browse files
committed
fdopen fix in keygen utility
1 parent c25f6a0 commit 12db568

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

ssh-keygen.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -990,6 +990,11 @@ do_gen_all_hostkeys(struct passwd *pw)
990990
}
991991
sshkey_free(private);
992992
strlcat(identity_file, ".pub", sizeof(identity_file));
993+
#ifdef WINDOWS
994+
if ((f = fopen(identity_file, "w")) == NULL) {
995+
error("fopen %s failed: %s", identity_file, strerror(errno));
996+
/* TODO - set permissions on file */
997+
#else
993998
fd = open(identity_file, O_WRONLY | O_CREAT | O_TRUNC, 0644);
994999
if (fd == -1) {
9951000
error("Could not save your public key in %s",
@@ -999,9 +1004,11 @@ do_gen_all_hostkeys(struct passwd *pw)
9991004
continue;
10001005
}
10011006
f = fdopen(fd, "w");
1007+
10021008
if (f == NULL) {
10031009
error("fdopen %s failed", identity_file);
10041010
close(fd);
1011+
#endif
10051012
sshkey_free(public);
10061013
first = 0;
10071014
continue;
@@ -2765,10 +2772,10 @@ main(int argc, char **argv)
27652772
printf("Your identification has been saved in %s.\n", identity_file);
27662773

27672774
strlcat(identity_file, ".pub", sizeof(identity_file));
2768-
/* TODO - for windows call fopen directly*/
27692775
#ifdef WINDOWS
27702776
if ((f = fopen(identity_file, "w")) == NULL)
27712777
fatal("fopen %s failed: %s", identity_file, strerror(errno));
2778+
/* TODO - set permissions on file */
27722779
#else
27732780
if ((fd = open(identity_file, O_WRONLY|O_CREAT|O_TRUNC, 0644)) == -1)
27742781
fatal("Unable to save public key to %s: %s",

0 commit comments

Comments
 (0)