diff options
author | Federico Vaga <federico.vaga@vaga.pv.it> | 2017-04-23 12:22:55 +0200 |
---|---|---|
committer | Steven Rostedt (VMware) <rostedt@goodmis.org> | 2017-04-26 10:49:42 -0400 |
commit | 53e9b788d537ad9735c3186d93f14d1efbf62f4d (patch) | |
tree | 861220f233c6a9acab1052e0b19c055f7ca06e31 | |
parent | 3b43d0a77d7178b797d6ba38ca21b8286b647afd (diff) | |
download | trace-cmd-53e9b788d537ad9735c3186d93f14d1efbf62f4d.tar.gz |
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.
Link: http://lkml.kernel.org/r/20170423102258.21609-3-federico.vaga@vaga.pv.it
Signed-off-by: Federico Vaga <federico.vaga@vaga.pv.it>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
-rw-r--r-- | plugin_python.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/plugin_python.c b/plugin_python.c index d3da8b08..29976793 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) { |