From: Taylor Blau <me@ttaylorr.com>
To: Patrick Steinhardt <ps@pks.im>
Cc: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>,
Elijah Newren <newren@gmail.com>
Subject: Re: [PATCH 1/3] http.c: introduce `set_long_from_env()` for convenience
Date: Wed, 19 Mar 2025 14:02:53 -0400 [thread overview]
Message-ID: <Z9sGzWNU5Gn5c/+8@nand.local> (raw)
In-Reply-To: <Z9rqK8QSs2dA7t6S@pks.im>
On Wed, Mar 19, 2025 at 05:00:43PM +0100, Patrick Steinhardt wrote:
> > diff --git a/http.c b/http.c
> > index 0c9a872809..be564fd520 100644
> > --- a/http.c
> > +++ b/http.c
> > @@ -1256,10 +1256,15 @@ static void set_from_env(char **var, const char *envname)
> > }
> > }
> >
> > +static void set_long_from_env(long *var, const char *envname)
> > +{
> > + const char *val = getenv(envname);
> > + if (val)
> > + *var = strtol(val, NULL, 10);
> > +}
>
> Hm. We don't perform any error checking at all for whether or not the
> value of the environment variable is a valid integer. This isn't a new
> issue introduced by your patch, but now that we have a central place
> where it's being parsed I wonder whether we should be checking for
> errors?
Yeah, I guess it's technically not "new" in the sense that we were
already doing:
xyz = getenv("XYZ");
if (xyz)
*var = strtol(xyz, NULL, 10);
I suppose we could do something like:
--- 8< ---
diff --git a/http.c b/http.c
index c13c7da530..6b01ad7a53 100644
--- a/http.c
+++ b/http.c
@@ -1280,8 +1280,20 @@ static void set_from_env(char **var, const char *envname)
static void set_long_from_env(long *var, const char *envname)
{
const char *val = getenv(envname);
- if (val)
- *var = strtol(val, NULL, 10);
+ if (val) {
+ long tmp;
+ char *endp;
+ errno = 0;
+ tmp = strtol(val, &endp, 10);
+ if (errno)
+ warning_errno(_("failed to parse '%s' (%s) as long"),
+ envname, val);
+ else if (endp == val)
+ warning(_("failed to parse '%s' (%s) as long"), envname,
+ val);
+ else
+ *var = tmp;
+ }
}
void http_init(struct remote *remote, const char *url, int proactive_auth)
--- >8 ---
On top, but TBH I'm not sure how much value it adds. This is only used
for reading GIT_XYZ variables out of the environment, and we're already
pretty lax about strtol() errors in other places. Since this isn't the
interface we expect users to use, I'm OK to punt on it for now unless
you feel strongly otherwise.
Thanks,
Taylor
next prev parent reply other threads:[~2025-03-19 18:02 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-18 22:21 [PATCH 0/3] http: support fine-tuning curl's keepalive behavior Taylor Blau
2025-03-18 22:21 ` [PATCH 1/3] http.c: introduce `set_long_from_env()` for convenience Taylor Blau
2025-03-19 16:00 ` Elijah Newren
2025-03-19 16:00 ` Patrick Steinhardt
2025-03-19 18:02 ` Taylor Blau [this message]
2025-03-18 22:21 ` [PATCH 2/3] http.c: inline `set_curl_keepalive()` Taylor Blau
2025-03-19 16:01 ` Elijah Newren
2025-03-18 22:21 ` [PATCH 3/3] http.c: allow custom TCP keepalive behavior via config Taylor Blau
2025-03-19 16:00 ` Patrick Steinhardt
2025-03-19 16:15 ` Elijah Newren
2025-03-19 18:05 ` Taylor Blau
2025-03-19 22:23 ` [PATCH v2 0/4] http: support fine-tuning curl's keepalive behavior Taylor Blau
2025-03-19 22:23 ` [PATCH v2 1/4] http.c: remove unnecessary casts to long Taylor Blau
2025-03-19 22:23 ` [PATCH v2 2/4] http.c: introduce `set_long_from_env()` for convenience Taylor Blau
2025-03-20 5:24 ` Patrick Steinhardt
2025-04-01 9:10 ` Jeff King
2025-03-19 22:23 ` [PATCH v2 3/4] http.c: inline `set_curl_keepalive()` Taylor Blau
2025-04-01 9:12 ` Jeff King
2025-03-19 22:23 ` [PATCH v2 4/4] http.c: allow custom TCP keepalive behavior via config Taylor Blau
2025-04-01 9:16 ` Jeff King
2025-03-19 22:49 ` [PATCH v2 0/4] http: support fine-tuning curl's keepalive behavior Elijah Newren
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=Z9sGzWNU5Gn5c/+8@nand.local \
--to=me@ttaylorr.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=newren@gmail.com \
--cc=ps@pks.im \
/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).