[PATCH 0/3] cmd: setexpr: add fmt format string operation
Wolfgang Denk
wd at denx.de
Tue Jun 29 12:40:51 CEST 2021
Dear Roland,
In message <a463f32f-8ef0-6973-f1c3-a881ee6e5d26 at 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 at 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
More information about the U-Boot
mailing list