public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Wolfgang Denk <wd@denx.de>
To: "Roland Gaudig (OSS)" <roland.gaudig-oss@weidmueller.com>
Cc: u-boot@lists.denx.de, "Simon Glass" <sjg@chromium.org>,
	"Roland Gaudig" <roland.gaudig@weidmueller.com>,
	"Alex Nemirovsky" <alex.nemirovsky@cortina-access.com>,
	"Bin Meng" <bmeng.cn@gmail.com>,
	"Heinrich Schuchardt" <xypron.glpk@gmx.de>,
	"Marek Behún" <marek.behun@nic.cz>,
	"Patrick Delaunay" <patrick.delaunay@foss.st.com>,
	"Rayagonda Kokatanur" <rayagonda.kokatanur@broadcom.com>,
	"Robert Marko" <robert.marko@sartura.hr>,
	"Sean Anderson" <seanga2@gmail.com>,
	"Stefan Bosch" <stefan_b@posteo.net>,
	"Weijie Gao" <weijie.gao@mediatek.com>
Subject: Re: [PATCH 0/3] cmd: setexpr: add fmt format string operation
Date: Tue, 29 Jun 2021 12:40:51 +0200	[thread overview]
Message-ID: <89618.1624963251@gemini.denx.de> (raw)
In-Reply-To: <a463f32f-8ef0-6973-f1c3-a881ee6e5d26@weidmueller.com>

Dear Roland,

In message <a463f32f-8ef0-6973-f1c3-a881ee6e5d26@weidmueller.com> you wrote:
>
> > These are two pretty unfortunate restrictions.  I guess it should
> > not be too hard to avoid both of these.  Can you please give it a
> > try?
>
> I think it is possible to allow more than one format parameter or more
> types. But it would make checking much more difficult.

Maybe we need _less_ checking, not more - and maybe the needed
checking is already done in the *printf() code?

> I think just passing the format string directly to sprintf should be
> avoided because it is unsafe. For example
>
> => setexpr foo fmt %s 0xffffffff
>
> would surely lead to access on memory location outside the variable
> where 0xffffffff is stored.

Only if you make the wrong assumptions.  I would expect this to
result in

	foo=0xffffffff

in the same way as the bash builting gives

	$ printf '%s\n' 0xffffffff
	0xffffffff

> > => setexpr foo fmt "%0x08x-%s-%d-%s" $a $b $c $d
>
> I think the only way to support such expressions in a save way would
> be implementing an own format string parser for setexpr with

Maybe it makes sense to have a look at the bash code?

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd@denx.de
How many seconds are there in a year? If I tell you there are 3.155 x
10^7, you won't even try to remember it. On the other hand, who could
forget that, to within half a percent, pi seconds is  a  nanocentury.
                                               -- Tom Duff, Bell Labs

  parent reply	other threads:[~2021-06-29 10:41 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-28 15:17 [PATCH 0/3] cmd: setexpr: add fmt format string operation Roland Gaudig
2021-06-28 15:17 ` [PATCH 1/3] " Roland Gaudig
2021-06-28 17:39   ` Rasmus Villemoes
2021-06-29  8:44     ` Wolfgang Denk
2021-06-29  8:41   ` Wolfgang Denk
2021-06-28 15:17 ` [PATCH 2/3] doc: usage: add description for setexpr command Roland Gaudig
2021-07-05 15:29   ` Simon Glass
2021-06-28 15:17 ` [PATCH 3/3] test: cmd: setexpr: add tests for format string operations Roland Gaudig
2021-07-05 15:29   ` Simon Glass
2021-06-29  8:37 ` [PATCH 0/3] cmd: setexpr: add fmt format string operation Wolfgang Denk
2021-06-29  9:41   ` Roland Gaudig (OSS)
2021-06-29 10:34     ` Marek Behun
2021-06-29 10:40     ` Wolfgang Denk [this message]
2021-06-30  8:30       ` Roland Gaudig (OSS)
2021-06-29 13:57   ` Sean Anderson
2021-06-29 15:13     ` Wolfgang Denk
2021-06-30 16:17       ` Sean Anderson
2021-06-30 17:11         ` Marek Behún
2021-07-02 10:50         ` Wolfgang Denk

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=89618.1624963251@gemini.denx.de \
    --to=wd@denx.de \
    --cc=alex.nemirovsky@cortina-access.com \
    --cc=bmeng.cn@gmail.com \
    --cc=marek.behun@nic.cz \
    --cc=patrick.delaunay@foss.st.com \
    --cc=rayagonda.kokatanur@broadcom.com \
    --cc=robert.marko@sartura.hr \
    --cc=roland.gaudig-oss@weidmueller.com \
    --cc=roland.gaudig@weidmueller.com \
    --cc=seanga2@gmail.com \
    --cc=sjg@chromium.org \
    --cc=stefan_b@posteo.net \
    --cc=u-boot@lists.denx.de \
    --cc=weijie.gao@mediatek.com \
    --cc=xypron.glpk@gmx.de \
    /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