Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1044929AbdDWKdZ (ORCPT ); Sun, 23 Apr 2017 06:33:25 -0400 Received: from mx.kolabnow.com ([95.128.36.1]:28234 "EHLO mx-out02.mykolab.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1044873AbdDWKdT (ORCPT ); Sun, 23 Apr 2017 06:33:19 -0400 X-Greylist: delayed 590 seconds by postgrey-1.27 at vger.kernel.org; Sun, 23 Apr 2017 06:33:19 EDT X-Spam-Flag: NO X-Spam-Score: -2.9 From: Federico Vaga To: Steven Rostedt Cc: LKML , Federico Vaga Subject: [PATCH 2/5] plugin:python: check asprintf() errors Date: Sun, 23 Apr 2017 12:22:55 +0200 Message-Id: <20170423102258.21609-3-federico.vaga@vaga.pv.it> In-Reply-To: <20170423102258.21609-1-federico.vaga@vaga.pv.it> References: <20170423102258.21609-1-federico.vaga@vaga.pv.it> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1174 Lines: 42 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 --- 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