From: "Phillip Wood via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Fabian Stelzer <fs@gigacodes.de>,
Phillip Wood <phillip.wood@dunelm.org.uk>,
Phillip Wood <phillip.wood@dunelm.org.uk>
Subject: [PATCH v2] ssh signing: return an error when signature cannot be read
Date: Tue, 04 Oct 2022 10:01:34 +0000 [thread overview]
Message-ID: <pull.1371.v2.git.1664877694430.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.1371.git.1664789075343.gitgitgadget@gmail.com>
From: Phillip Wood <phillip.wood@dunelm.org.uk>
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 <phillip.wood@dunelm.org.uk>
---
ssh signing: return an error when signature cannot be read
Thanks to Junio for his comments. I've updated the patch to always use
unlink_or_warn() to remove the signature file as it does not warn on
missing files.
V1 cover letter
This patch is based on maint. In the longer term the code could be
simplified by using pipes rather than tempfiles as we do for gpg.
ssh-keygen has supported reading the data to be signed from stdin and
writing the signature to stdout since it introduced signing.
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1371%2Fphillipwood%2Fssh-signing-return-error-on-missing-signature-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1371/phillipwood/ssh-signing-return-error-on-missing-signature-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/1371
Range-diff vs v1:
1: 6f569ac0f48 ! 1: 1db8af68fce ssh signing: return an error when signature cannot be read
@@ Commit message
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. If we
- cannot read the file it may be missing so ignore any errors from
- unlink() when we try to remove it.
+ 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 <phillip.wood@dunelm.org.uk>
@@ gpg-interface.c: static int sign_buffer_ssh(struct strbuf *buffer, struct strbuf
+ ret = error_errno(
_("failed reading ssh signing data buffer from '%s'"),
ssh_signature_filename.buf);
-+ unlink(ssh_signature_filename.buf);
+ goto out;
}
- unlink_or_warn(ssh_signature_filename.buf);
+- unlink_or_warn(ssh_signature_filename.buf);
+-
+ /* Strip CR from the line endings, in case we are on Windows. */
+ remove_cr_after(signature, bottom);
+@@ gpg-interface.c: out:
+ delete_tempfile(&key_file);
+ if (buffer_file)
+ delete_tempfile(&buffer_file);
++ if (ssh_signature_filename.len)
++ unlink_or_warn(ssh_signature_filename.buf);
+ strbuf_release(&signer_stderr);
+ strbuf_release(&ssh_signature_filename);
+ FREE_AND_NULL(ssh_signing_key_file);
gpg-interface.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/gpg-interface.c b/gpg-interface.c
index 947b58ad4da..b5c2bbb3b91 100644
--- a/gpg-interface.c
+++ b/gpg-interface.c
@@ -1043,12 +1043,11 @@ static int sign_buffer_ssh(struct strbuf *buffer, struct strbuf *signature,
strbuf_addbuf(&ssh_signature_filename, &buffer_file->filename);
strbuf_addstr(&ssh_signature_filename, ".sig");
if (strbuf_read_file(signature, ssh_signature_filename.buf, 0) < 0) {
- error_errno(
+ ret = error_errno(
_("failed reading ssh signing data buffer from '%s'"),
ssh_signature_filename.buf);
+ goto out;
}
- unlink_or_warn(ssh_signature_filename.buf);
-
/* Strip CR from the line endings, in case we are on Windows. */
remove_cr_after(signature, bottom);
@@ -1057,6 +1056,8 @@ out:
delete_tempfile(&key_file);
if (buffer_file)
delete_tempfile(&buffer_file);
+ if (ssh_signature_filename.len)
+ unlink_or_warn(ssh_signature_filename.buf);
strbuf_release(&signer_stderr);
strbuf_release(&ssh_signature_filename);
FREE_AND_NULL(ssh_signing_key_file);
base-commit: a0feb8611d4c0b2b5d954efe4e98207f62223436
--
gitgitgadget
next prev parent reply other threads:[~2022-10-04 10:01 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-03 9:24 [PATCH] ssh signing: return an error when signature cannot be read Phillip Wood via GitGitGadget
2022-10-03 16:13 ` Junio C Hamano
2022-10-04 10:01 ` Phillip Wood via GitGitGadget [this message]
2022-10-06 8:28 ` [PATCH v2] " Fabian Stelzer
2022-10-06 13:05 ` Phillip Wood
2022-10-06 14:19 ` Fabian Stelzer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=pull.1371.v2.git.1664877694430.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=fs@gigacodes.de \
--cc=git@vger.kernel.org \
--cc=phillip.wood@dunelm.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).