lkml.org 
[lkml]   [2017]   [Apr]   [23]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 2/5] plugin:python: check asprintf() errors
Date
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@vaga.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
\
 
 \ /
  Last update: 2017-04-23 12:33    [W:0.040 / U:1.304 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site