[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20170423102258.21609-3-federico.vaga@vaga.pv.it>
Date: Sun, 23 Apr 2017 12:22:55 +0200
From: Federico Vaga <federico.vaga@...a.pv.it>
To: Steven Rostedt <rostedt@...dmis.org>
Cc: LKML <linux-kernel@...r.kernel.org>,
Federico Vaga <federico.vaga@...a.pv.it>
Subject: [PATCH 2/5] plugin:python: check asprintf() errors
The code was validating the string but the man page for asprintf(3)
says clearly:
--------
If memory allocation wasn't possible, or some other error occurs,
these functions will return -1, and the contents of strp are undefined.
--------
So, we cannot really rely on the returned string pointer.
Signed-off-by: Federico Vaga <federico.vaga@...a.pv.it>
---
plugin_python.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/plugin_python.c b/plugin_python.c
index d3da8b0..2997679 100644
--- a/plugin_python.c
+++ b/plugin_python.c
@@ -24,6 +24,7 @@ static int load_plugin(struct pevent *pevent, const char *path,
const char *name, void *data)
{
PyObject *globals = data;
+ int err;
int len = strlen(path) + strlen(name) + 2;
int nlen = strlen(name) + 1;
char *full = malloc(len);
@@ -41,9 +42,9 @@ static int load_plugin(struct pevent *pevent, const char *path,
strcpy(n, name);
n[nlen - 4] = '\0';
- asprintf(&load, pyload, full, n);
- if (!load)
- return -ENOMEM;
+ err = asprintf(&load, pyload, full, n);
+ if (err < 0)
+ return err;
res = PyRun_String(load, Py_file_input, globals, globals);
if (!res) {
--
2.9.3
Powered by blists - more mailing lists