Skip to content

Commit 673b8a4

Browse files
committed
use ifdef to prevent breaking core SSH code
1 parent 4ade05a commit 673b8a4

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

ssh-keygen.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,7 +1468,7 @@ do_change_comment(struct passwd *pw)
14681468
struct sshkey *public;
14691469
struct stat st;
14701470
FILE *f;
1471-
int r;
1471+
int r, fd;
14721472

14731473
if (!have_identity)
14741474
ask_filename(pw, "Enter file in which the key is");
@@ -1541,9 +1541,18 @@ do_change_comment(struct passwd *pw)
15411541
sshkey_free(private);
15421542

15431543
strlcat(identity_file, ".pub", sizeof(identity_file));
1544-
f = fopen(identity_file, "w");
1545-
if (f == NULL)
1544+
if ((fd = open(identity_file, O_WRONLY | O_CREAT | O_TRUNC, 0644)) == -1)
1545+
fatal("Could not save your public key in %s: %s",
1546+
identity_file, strerror(errno));
1547+
#ifdef WINDOWS
1548+
/* Windows POSIX adpater does not support fdopen() on open(file)*/
1549+
close(fd);
1550+
if ((f = fopen(identity_file, "w")) == NULL)
15461551
fatal("fopen %s failed: %s", identity_file, strerror(errno));
1552+
#else /* !WINDOWS */
1553+
if ((f = fdopen(fd, "w")) == NULL)
1554+
fatal("fdopen %s failed: %s", identity_file, strerror(errno));
1555+
#endif /* !WINDOWS */
15471556
if ((r = sshkey_write(public, f)) != 0)
15481557
fatal("write key failed: %s", ssh_err(r));
15491558
sshkey_free(public);

0 commit comments

Comments
 (0)