For an empty prefix, this function returns a value that can't be distinguished from a non-matching prefix. This is wrong, since an empty prefix is present in every string, and has resulted in bugs in code that called this function without knowing this issue. Let's document it. Closes: https://lore.kernel.org/linux-hardening/20261104-fwnode-for-each-prop-v1-1-6e28fe1c72c4@oss.qualcomm.com/ Reported-by: Bartosz Golaszewski Signed-off-by: Alejandro Colomar --- include/linux/string.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/linux/string.h b/include/linux/string.h index a6a1953c52e3..574eaa8ff527 100644 --- a/include/linux/string.h +++ b/include/linux/string.h @@ -586,6 +586,10 @@ static inline char *strprefix(const char *s, const char *prefix) * This is similar to strprefix(), but returns an offset instead of * a pointer. * + * Unlike for strprefix(), if the prefix is an empty string, the + * behavior is undefined. If you need to support arbitrary prefixes, + * use strprefix(). + * * Returns: * * strlen(@prefix) if @str starts with @prefix * * 0 if @str does not start with @prefix -- 2.55.0