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)
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 );
You can’t perform that action at this time.
0 commit comments