Off-by-one in arch/mips/bcm47xx/time.c (was: [PATCH v6 02/19] string: Add strprefix())
From: Alejandro Colomar
Date: Sat Nov 14 2026 - 14:49:40 EST
Hi Hauke,
> Date: 2026-11-14 07:53:25-0800
> From: Joe Perches <joe@xxxxxxxxxxx>
>
[...]
> And these are all candidates for converted uses to
> whatever is the function name or steq:
>
> $ git grep -P '[^w]strncmp\s*\(\s*[\w\.\-\>\s]*,\s*\"\w*"\s*,\s*\d+\s*\)' -- '*.[ch]' | wc -l
> 946
Looking at those, I've seen a bug in BCM47XX, introduced in 2224de9d152b
(2013-10-29; "MIPS: BCM47XX: Fix clock detection for BCM5354 with 200MHz
clock").
Look at this line of code:
$ grep strncmp arch/mips/bcm47xx/time.c
if (len >= 0 && !strncmp(buf, "200", 4))
That strncmp(3) call is wrong, as it's really behaving as strcmp(3),
since the 4 is off-by-one. I'd like to know what was the intention.
Was it meant to be !strncmp(buf, "200", 3)? Or was it meant to be just
!strcmp(buf, "200")?
Have a lovely night!
Alex
--
<https://www.alejandro-colomar.es>
Attachment:
signature.asc
Description: PGP signature