From: Junio C Hamano <gitster@pobox.com>
To: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Cc: git@vger.kernel.org, Max Gautier <max.gautier@redhat.com>,
Jeff King <peff@peff.net>
Subject: Re: [PATCH] gpg-interface: lazily initialize and read the configuration
Date: Wed, 08 Feb 2023 18:05:57 -0800 [thread overview]
Message-ID: <xmqq5ycbpp8a.fsf@gitster.g> (raw)
In-Reply-To: <230209.86fsbfznot.gmgdl@evledraar.gmail.com> ("Ævar Arnfjörð Bjarmason"'s message of "Thu, 09 Feb 2023 01:17:39 +0100")
Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
> One thing left un-noted here is that this will defer any errors in the
> config now until use (or lazy init), so e.g.:
>
> git -c gpg.mintrustlevel=bad show --show-signature
>
> Used to exit with code 128 and an error, but will now (at least for me)
> proceed to run show successfully.
That one is probably a good thing. We shouldn't interrupt users for
a misspelt configuration value that the user is not using.
>> @@ -632,6 +644,8 @@ int check_signature(struct signature_check *sigc,
>> struct gpg_format *fmt;
>> int status;
>>
>> + gpg_interface_lazy_init();
>> +
>> sigc->result = 'N';
>> sigc->trust_level = -1;
>
> This is needed, because we need "configured_min_trust_level" populated.
I specifically did not want anybody to start doing this line of
analysis, because it will add unnecessary bugs, and also introduce
maintenance problems. You may be able to grab the current state of
the code, but that will get stale and won't be a good guide to keep
our code robust.
>> @@ -695,11 +709,13 @@ int parse_signature(const char *buf, size_t size, struct strbuf *payload, struct
>>
>> void set_signing_key(const char *key)
>> {
>> + gpg_interface_lazy_init();
>> +
>> free(configured_signing_key);
>> configured_signing_key = xstrdup(key);
>> }
>
> But this is not, we could say that we're doing it for good measure, but
> it's hard to imagine a scenario where we would end up actually needing
> lazy init here. we'll just set a variable here, which...
And especially this one, we must have init or we'll be incorrect, I
think. There is a direct set_signing_key() caller (I think in "git
tag") that does not come from the git_config() callback route.
Without the lazy initialization, we'd get configured_signing_key
from the config because early in the start-up sequence of the
command we would do git_gpg_config() via git_config(), and then try
to process "-u keyid" by calling this one again.
If you forget to lazily initialize here, configured_signing_key gets
the keyid obtained via "-u keyid", and then when control reaches the
real signing function, we'd realize that we still haven't
initialized ourselves. And we call lazy init, which finds
configured keyID, which is very likely different from "-u keyid"
(the user would not be passing "-u keyid" from the command line to
override, if that is the same as the configured one), and clobber
it.
Thanks.
next prev parent reply other threads:[~2023-02-09 2:06 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-08 15:56 git rev-list fails to verify ssh-signed commits (but git log works) Max Gautier
2023-02-08 16:43 ` Jeff King
2023-02-08 17:56 ` Junio C Hamano
2023-02-08 18:20 ` Junio C Hamano
2023-02-08 20:31 ` [PATCH] gpg-interface: lazily initialize and read the configuration Junio C Hamano
2023-02-09 0:17 ` Ævar Arnfjörð Bjarmason
2023-02-09 2:05 ` Junio C Hamano [this message]
2023-02-09 2:24 ` Ævar Arnfjörð Bjarmason
2023-02-09 12:49 ` Jeff King
2023-02-09 16:38 ` Junio C Hamano
2023-02-09 20:24 ` [PATCH v2] " Junio C Hamano
2023-02-26 22:40 ` Jeff King
2023-02-27 16:00 ` Junio C Hamano
2023-03-08 8:34 ` Ævar Arnfjörð Bjarmason
2023-03-09 3:28 ` Jeff King
2023-03-09 17:03 ` Junio C Hamano
2023-03-10 9:01 ` Jeff King
2023-02-09 12:41 ` git rev-list fails to verify ssh-signed commits (but git log works) Jeff King
2023-02-09 16:44 ` Junio C Hamano
2023-02-08 17:00 ` Junio C Hamano
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=xmqq5ycbpp8a.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=avarab@gmail.com \
--cc=git@vger.kernel.org \
--cc=max.gautier@redhat.com \
--cc=peff@peff.net \
/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).