Skip to content

Commit 233f56e

Browse files
spikehjfvogel
authored andcommitted
tools: ynl-gen: validate 0 len strings from kernel
[ Upstream commit 4720f9707c783f642332dee3d56dccaefa850e42 ] 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]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]> Signed-off-by: Sasha Levin <[email protected]> (cherry picked from commit 511ea82e344e044aad215a4456ab400a70565e54) Signed-off-by: Jack Vogel <[email protected]>
1 parent e731f0e commit 233f56e

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

tools/net/ynl/lib/ynl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ int ynl_attr_validate(struct ynl_parse_arg *yarg, const struct nlattr *attr)
364364
"Invalid attribute (binary %s)", policy->name);
365365
return -1;
366366
case YNL_PT_NUL_STR:
367-
if ((!policy->len || len <= policy->len) && !data[len - 1])
367+
if (len && (!policy->len || len <= policy->len) && !data[len - 1])
368368
break;
369369
yerr(yarg->ys, YNL_ERROR_ATTR_INVALID,
370370
"Invalid attribute (string %s)", policy->name);

0 commit comments

Comments
 (0)