[PATCH v2] env: mmc: Correct partition comparison in mmc_offset_try_partition

Hoyeonjiki Kim jigi.kim at gmail.com
Sun Nov 15 18:01:07 CET 2020


Dear Wolfgang Denk,

On Mon, Nov 16, 2020 at 1:36 AM Wolfgang Denk <wd at denx.de> wrote:
>
> Dear Hoyeonjiki Kim,
>
> In message <CAL9K-_jni+850m5Zf7QPPeM+dmSxqSZ5AgirDnzE_2uxrO4Akg at mail.gmail.com> you wrote:
> >
> > As you referred, `strcmp` suffers with non-null terminated string(s).
> > I'd also checked if using `strcmp` can cause some issues and
> > seems it's **guaranteed** that there is no such issue in this context.
>
> You ar4e probably right, but the problem with this approach is that
> what today is a verified context, may tomoroow change - a new use
> case may be added, which is not aware of this potential problem, and
> which thus triggers a (foreseeable and avoidable bug).

Absolutely. I got your point and agree with that.

>
> > But if we need to specify that the context will not suffer anyway, there
> > is an option to use `strncmp` with `PART_NAME_LEN` as max count param.
> >
> > `PART_NAME_LEN` is the size of `info.name` which is a character buffer.
>
> If we know we size  (and apparewntly we do), we should use this with
> strncmp().  Just in case...

Because in this context, we can use 'sizeof(info.name)' as max count,
I think I can bring v3 with strncmp().

Thanks for the feedback.

Best Regards,
Hoyeonjiki Kim

>
> 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
> It's not what you do, it's how you do what you do!  - Jordan D. Ulmer


More information about the U-Boot mailing list