]> git.proxmox.com Git - mirror_frr.git/commitdiff
lib: use `prefix` for yang get prefix wrapper
authorRafael Zalamena <rzalamena@opensourcerouting.org>
Fri, 11 Oct 2019 23:15:46 +0000 (20:15 -0300)
committerRafael Zalamena <rzalamena@opensourcerouting.org>
Sat, 12 Oct 2019 01:41:17 +0000 (22:41 -0300)
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>
lib/yang_wrappers.c
lib/yang_wrappers.h

index 50225f35a08e8c41da808d277aec851350888061..a308b18b7316aac687c1ec46e8877f47c7538cc1 100644 (file)
@@ -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, ...)
index 1a30ff3686240450aa3f6de55d08f6426233ed96..10d1ea314fc389f241161174f5463f5074d0d302 100644 (file)
@@ -118,7 +118,7 @@ extern void yang_get_default_string_buf(char *buf, size_t size,
 extern void yang_str2prefix(const char *value, union prefixptr prefix);
 extern struct yang_data *yang_data_new_prefix(const char *xpath,
                                              union prefixconstptr prefix);
-extern void yang_dnode_get_prefix(union prefixptr prefix,
+extern void yang_dnode_get_prefix(struct prefix *prefix,
                                  const struct lyd_node *dnode,
                                  const char *xpath_fmt, ...);
 extern void yang_get_default_prefix(union prefixptr var, const char *xpath_fmt,