From bd9caa8f11d931db21f628ad61be042147861ad4 Mon Sep 17 00:00:00 2001
|
|
From: Mark Stapp <mjs@voltanet.io>
|
|
Date: Fri, 26 Feb 2021 11:16:09 -0500
|
|
Subject: [PATCH 1/3] lib: fix some misc SA warnings
|
|
|
|
- clippy.c: fix valid memleak
|
|
- defun_lex.l: suppress warnings in generated code
|
|
- northbound_cli.c: suppress warning in eldritch libyang macro
|
|
|
|
Signed-off-by: Quentin Young <qlyoung@nvidia.com>
|
|
---
|
|
lib/clippy.c | 4 +++-
|
|
lib/defun_lex.l | 4 ++++
|
|
lib/northbound_cli.c | 12 ++++++++++++
|
|
3 files changed, 19 insertions(+), 1 deletion(-)
|
|
|
|
--- a/lib/clippy.c
|
|
+++ b/lib/clippy.c
|
|
@@ -51,7 +51,8 @@ int main(int argc, char **argv)
|
|
#if PY_VERSION_HEX >= 0x03040000 /* 3.4 */
|
|
Py_SetStandardStreamEncoding("UTF-8", NULL);
|
|
#endif
|
|
- Py_SetProgramName(wconv(argv[0]));
|
|
+ wchar_t *name = wconv(argv[0]);
|
|
+ Py_SetProgramName(name);
|
|
PyImport_AppendInittab("_clippy", command_py_init);
|
|
|
|
Py_Initialize();
|
|
@@ -67,6 +68,8 @@ int main(int argc, char **argv)
|
|
fp = fopen(pyfile, "r");
|
|
if (!fp) {
|
|
fprintf(stderr, "%s: %s\n", pyfile, strerror(errno));
|
|
+
|
|
+ free(name);
|
|
return 1;
|
|
}
|
|
} else {
|
|
@@ -85,6 +88,8 @@ int main(int argc, char **argv)
|
|
if (PyRun_AnyFile(fp, pyfile)) {
|
|
if (PyErr_Occurred())
|
|
PyErr_Print();
|
|
+
|
|
+ free(name);
|
|
return 1;
|
|
}
|
|
Py_Finalize();
|
|
@@ -93,6 +98,7 @@ int main(int argc, char **argv)
|
|
for (int i = 1; i < argc; i++)
|
|
free(wargv[i - 1]);
|
|
#endif
|
|
+ free(name);
|
|
free(wargv);
|
|
return 0;
|
|
}
|
|
--- a/lib/defun_lex.l
|
|
+++ b/lib/defun_lex.l
|
|
@@ -80,6 +80,8 @@ static void extendbuf(char **what, const
|
|
}
|
|
#define extend(x) extendbuf(&value, x)
|
|
|
|
+#ifndef __clang_analyzer__
|
|
+
|
|
%}
|
|
|
|
ID [A-Za-z0-9_]+
|
|
@@ -157,6 +159,8 @@ SPECIAL [(),]
|
|
|
|
%%
|
|
|
|
+#endif /* __clang_analyzer__ */
|
|
+
|
|
static int yylex_clr(char **retbuf)
|
|
{
|
|
int rv = def_yylex();
|
|
--- a/lib/northbound_cli.c
|
|
+++ b/lib/northbound_cli.c
|
|
@@ -595,7 +595,19 @@ void nb_cli_show_dnode_cmds(struct vty *
|
|
(*nb_node->cbs.cli_show_end)(vty, parent);
|
|
}
|
|
|
|
+ /*
|
|
+ * There is a possible path in this macro that ends up
|
|
+ * dereferencing child->parent->parent. We just null checked
|
|
+ * child->parent by checking (ly_iter_next_up(child) != NULL)
|
|
+ * above.
|
|
+ *
|
|
+ * I am not sure whether it is possible for the other
|
|
+ * conditions within this macro guarding the problem
|
|
+ * dereference to be satisfied when child->parent == NULL.
|
|
+ */
|
|
+#ifndef __clang_analyzer__
|
|
LY_TREE_DFS_END(root, next, child);
|
|
+#endif
|
|
}
|
|
}
|
|
|