mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <sha@pengutronix.de>
To: Ahmad Fatoum <a.fatoum@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH] env: let setenv() take printf arguments
Date: Mon, 20 Jun 2022 10:16:23 +0200	[thread overview]
Message-ID: <20220620081623.GO1615@pengutronix.de> (raw)
In-Reply-To: <45231568-198c-fd4d-713e-26f002b6257d@pengutronix.de>

On Mon, Jun 20, 2022 at 09:59:00AM +0200, Ahmad Fatoum wrote:
> Hello Sascha,
> 
> On 20.06.22 09:47, Sascha Hauer wrote:
> > On Mon, Jun 20, 2022 at 09:21:39AM +0200, Ahmad Fatoum wrote:
> >> From: Sascha Hauer <s.hauer@pengutronix.de>
> >>
> >> It's a common pattern to (ba)sprintf to a string and then call setenv()
> >> with this string. Let setenv() take printf arguments to make that
> >> easier. To avoid the overhead that goes with changing other callers
> >> to using setenv(var, "%s", val) to avoid security implications (and
> >> GCC warnings), fallback to the non-formatted version when there are
> >> only two arguments.
> >>
> >> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> >> [afa: fall back to non-formatted version on old two arg version]
> >> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> >> ---
> >> Thoughts?
> > 
> > While I'm impressed by this macro I don't like this very much. My desire
> > was to simplify things, now with this patch I'm no longer sure I reached
> > that goal.
> 
> Usage _is_ simpler. Declaration indeed looks a bit odd, but ¯\_(ツ)_/¯
> 
> > 
> > Alternatively we could
> > 
> > a) Drop the original patch
> > b) Replace the problematic places with setenv(foo, "%s", not_a_string_literal);
> > c) Pass -Wno-format-security, The Kernel does this for over a decade.
> 
> Then it probably needs to be revisited there then.
> 
> > My vote is c)
> 
> I am not fine with c). We don't sanitize for % in environment variable values
> and ignoring the warning has very clear security implications.

Ok, good point.

Then there's of course

d) keep setenv like it was before and introduce
   pr_setenv(const char *_name, const char *fmt, ...)

Sascha

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



      reply	other threads:[~2022-06-20  8:18 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-17  8:05 [PATCH 1/2] " Sascha Hauer
2022-06-17  8:05 ` [PATCH 2/2] treewide: Simplify setenv() calls Sascha Hauer
2022-06-17 21:53   ` Daniel Brát
2022-06-20  7:21     ` [PATCH] env: let setenv() take printf arguments Ahmad Fatoum
2022-06-20  7:47       ` Sascha Hauer
2022-06-20  7:59         ` Ahmad Fatoum
2022-06-20  8:16           ` Sascha Hauer [this message]

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=20220620081623.GO1615@pengutronix.de \
    --to=sha@pengutronix.de \
    --cc=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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