Skip to content

Commit 36fb0d0

Browse files
phillipwoodgitster
authored andcommitted
ssh signing: return an error when signature cannot be read
If the signature file cannot be read we print an error message but do not return an error to the caller. In practice it seems unlikely that the file would be unreadable if the call to ssh-keygen succeeds. The unlink_or_warn() call is moved to the end of the function so that we always try and remove the signature file. This isn't strictly necessary at the moment but it protects us against any extra code being added between trying to read the signature file and the cleanup at the end of the function in the future. unlink_or_warn() only prints a warning if it exists and cannot be removed. Signed-off-by: Phillip Wood <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a0feb86 commit 36fb0d0

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

gpg-interface.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,12 +1043,11 @@ static int sign_buffer_ssh(struct strbuf *buffer, struct strbuf *signature,
10431043
strbuf_addbuf(&ssh_signature_filename, &buffer_file->filename);
10441044
strbuf_addstr(&ssh_signature_filename, ".sig");
10451045
if (strbuf_read_file(signature, ssh_signature_filename.buf, 0) < 0) {
1046-
error_errno(
1046+
ret = error_errno(
10471047
_("failed reading ssh signing data buffer from '%s'"),
10481048
ssh_signature_filename.buf);
1049+
goto out;
10491050
}
1050-
unlink_or_warn(ssh_signature_filename.buf);
1051-
10521051
/* Strip CR from the line endings, in case we are on Windows. */
10531052
remove_cr_after(signature, bottom);
10541053

@@ -1057,6 +1056,8 @@ static int sign_buffer_ssh(struct strbuf *buffer, struct strbuf *signature,
10571056
delete_tempfile(&key_file);
10581057
if (buffer_file)
10591058
delete_tempfile(&buffer_file);
1059+
if (ssh_signature_filename.len)
1060+
unlink_or_warn(ssh_signature_filename.buf);
10601061
strbuf_release(&signer_stderr);
10611062
strbuf_release(&ssh_signature_filename);
10621063
FREE_AND_NULL(ssh_signing_key_file);

0 commit comments

Comments
 (0)