tools: ynl-gen: validate 0 len strings from kernel
Subsystems (3)
PATCH 1/1 tools: ynl-gen: validate 0 len strings from kernel
Strings from the kernel are guaranteed to be null terminated and ynl_attr_validate() checks for this. But it doesn't check if the string has a len of 0, which would cause problems when trying to access data[len - 1]. Fix this by checking that len is positive.
--- tools/net/ynl/lib/ynl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/net/ynl/lib/ynl.c +1 -1
@@ -364,7 +364,7 @@ int ynl_attr_validate(struct ynl_parse_arg *yarg, const struct nlattr *attr) "Invalid attribute (binary %s)", policy->name);return -1 ;case YNL_PT_NUL_STR : -if ((!policy->len || len <= policy->len) && !data[len -1 ]) +if (len && (!policy->len || len <= policy->len) && !data[len -1 ])break ;yerr (yarg->ys,YNL_ERROR_ATTR_INVALID ,"Invalid attribute (string %s)" , policy->name);
Signature · 1 line
2.47.1
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 8 lines · On Fri, 2 May 2025 21:30:50 -0700 you wrote:
Strings from the kernel are guaranteed to be null terminated and
ynl_attr_validate()checks for this. But it doesn't check if the string has a len of 0, which would cause problems when trying to access data[len - 1]. Fix this by checking that len is positive.Signed-off-by David Wei <[email protected]>[...]
Here is the summary with links:
- [net-next,v1] tools: ynl-gen: validate 0 len strings from kernel
https://git.kernel.org/netdev/net/c/4720f9707c78
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html