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

Wolfgang Denk wd at denx.de
Sun Nov 15 17:36:34 CET 2020


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).

> 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...

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