[PATCH 2/5] plugin:python: check asprintf() errors

From: Federico Vaga
Date: Sun Apr 23 2017 - 06:33:27 EST


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@xxxxxxxxxx>
---
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