summaryrefslogtreecommitdiff
path: root/lib/yang_wrappers.c
diff options
context:
space:
mode:
authorRafael Zalamena <rzalamena@opensourcerouting.org>2019-10-11 20:15:46 -0300
committerRafael Zalamena <rzalamena@opensourcerouting.org>2019-10-11 22:41:17 -0300
commit46fcb2df90409e401223d29c6162753bf73fca64 (patch)
tree324c50ed09846248ec67f723c15a1100222c9a1d /lib/yang_wrappers.c
parent38e9efd85f68c115f2250d3a6e2249967b4b35b9 (diff)
lib: use `prefix` for yang get prefix wrapper
This change fixes a static analyzer warning and should also make us safer when using this function. At the moment the code that triggered the warning is the only one that uses this function. Passing anything other than `struct prefix` to `str2prefix` function is dangerous, because the structure might be smaller than expected and we might have an buffer overflow. Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
Diffstat (limited to 'lib/yang_wrappers.c')
-rw-r--r--lib/yang_wrappers.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/yang_wrappers.c b/lib/yang_wrappers.c
index 50225f35a0..a308b18b73 100644
--- a/lib/yang_wrappers.c
+++ b/lib/yang_wrappers.c
@@ -799,7 +799,7 @@ struct yang_data *yang_data_new_prefix(const char *xpath,
return yang_data_new(xpath, value_str);
}
-void yang_dnode_get_prefix(union prefixptr prefix, const struct lyd_node *dnode,
+void yang_dnode_get_prefix(struct prefix *prefix, const struct lyd_node *dnode,
const char *xpath_fmt, ...)
{
const struct lyd_node_leaf_list *dleaf;
@@ -816,9 +816,15 @@ void yang_dnode_get_prefix(union prefixptr prefix, const struct lyd_node *dnode,
YANG_DNODE_GET_ASSERT(dnode, xpath);
}
+ /*
+ * Initialize prefix to avoid static analyzer complaints about
+ * uninitialized memory.
+ */
+ memset(prefix, 0, sizeof(*prefix));
+
dleaf = (const struct lyd_node_leaf_list *)dnode;
assert(dleaf->value_type == LY_TYPE_STRING);
- (void)str2prefix(dleaf->value_str, prefix.p);
+ (void)str2prefix(dleaf->value_str, prefix);
}
void yang_get_default_prefix(union prefixptr var, const char *xpath_fmt, ...)