From f25820508687888a80af989c9c1f783e7b9245df Mon Sep 17 00:00:00 2001 From: David Wei Date: Wed, 30 Apr 2025 20:04:54 -0700 Subject: [PATCH] lib/ynl: reject strings with 0 len in ynl_attr_validate() Strings from kernel are always null terminated which is checked for but it currently assumes that the len is > 0. Check that this is true before trying to access the char at (len - 1). Signed-off-by: David Wei --- lib/ynl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ynl.c b/lib/ynl.c index 8062d0c..cb1adb9 100644 --- a/lib/ynl.c +++ b/lib/ynl.c @@ -426,7 +426,7 @@ int ynl_attr_validate(struct ynl_parse_arg* yarg, const struct nlattr* attr) { 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,