File tree Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -1468,7 +1468,7 @@ do_change_comment(struct passwd *pw)
1468
1468
struct sshkey * public ;
1469
1469
struct stat st ;
1470
1470
FILE * f ;
1471
- int r ;
1471
+ int r , fd ;
1472
1472
1473
1473
if (!have_identity )
1474
1474
ask_filename (pw , "Enter file in which the key is" );
@@ -1541,9 +1541,18 @@ do_change_comment(struct passwd *pw)
1541
1541
sshkey_free (private );
1542
1542
1543
1543
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 )
1546
1551
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 */
1547
1556
if ((r = sshkey_write (public , f )) != 0 )
1548
1557
fatal ("write key failed: %s" , ssh_err (r ));
1549
1558
sshkey_free (public );
You can’t perform that action at this time.
0 commit comments