Handle NULL returns from calloc() in sample plugins.
PATCH 1/1 Handle NULL returns from calloc() in sample plugins.
This is basic housekeeping, adding NULL checks to context initialization of the sample plugin collection which are missing it. Realistically, this can never happen, but since these are supposed to be "good examples", not checking calloc() return isn't one.
Trac: #587
--- sample/sample-plugins/defer/simple.c | 5 +++++ .../keying-material-exporter-demo/keyingmaterialexporter.c | 6 ++++++ sample/sample-plugins/log/log.c | 5 +++++ sample/sample-plugins/log/log_v3.c | 5 +++++ sample/sample-plugins/simple/simple.c | 5 +++++ 5 files changed, 26 insertions(+)
sample/sample-plugins/defer/simple.c +5 -0
@@ -141,6 +141,11 @@ openvpn_plugin_open_v1(unsigned int *type_mask, const char *argv[], const char ** Allocate our context */ context = (struct plugin_context *)calloc (1 ,sizeof (struct plugin_context )); +if (context ==NULL ) + { +printf ("PLUGIN: allocating memory for context failed\n" ); +return NULL ; + } context->test_deferred_auth =atoi_null0 (get_env ("test_deferred_auth" , envp));printf ("TEST_DEFERRED_AUTH %d\n" , context->test_deferred_auth);
sample/sample-plugins/keying-material-exporter-demo/keyingmaterialexporter.c +6 -0
@@ -92,6 +92,12 @@ openvpn_plugin_open_v3(const int version, {struct plugin *plugin =calloc (1 ,sizeof (*plugin)); +if (plugin ==NULL ) + { +printf ("PLUGIN: allocating memory for context failed\n" ); +return OPENVPN_PLUGIN_FUNC_ERROR ; + } + plugin->type =get_env ("remote_1" , args->envp) ?CLIENT :SERVER ; plugin->log = args->callbacks->plugin_log;
sample/sample-plugins/log/log.c +5 -0
@@ -78,6 +78,11 @@ openvpn_plugin_open_v1(unsigned int *type_mask, const char *argv[], const char ** Allocate our context */ context = (struct plugin_context *)calloc (1 ,sizeof (struct plugin_context )); +if (context ==NULL ) + { +printf ("PLUGIN: allocating memory for context failed\n" ); +return NULL ; + }/* * Set the username/password we will require.
sample/sample-plugins/log/log_v3.c +5 -0
@@ -113,6 +113,11 @@ openvpn_plugin_open_v3(const int v3structver,/* Allocate our context */ context = (struct plugin_context *)calloc (1 ,sizeof (struct plugin_context )); +if (context ==NULL ) + { +printf ("PLUGIN: allocating memory for context failed\n" ); +return OPENVPN_PLUGIN_FUNC_ERROR ; + }/* Set the username/password we will require. */ context->username ="foo" ;
sample/sample-plugins/simple/simple.c +5 -0
@@ -80,6 +80,11 @@ openvpn_plugin_open_v1(unsigned int *type_mask, const char *argv[], const char ** Allocate our context */ context = (struct plugin_context *)calloc (1 ,sizeof (struct plugin_context )); +if (context ==NULL ) + { +printf ("PLUGIN: allocating memory for context failed\n" ); +return NULL ; + }/* * Set the username/password we will require.
Signature · 1 line
2.26.2
Quoted 9 lines · Gert Doering
This is basic housekeeping, adding NULL checks to context initialization of the sample plugin collection which are missing it. Realistically, this can never happen, but since these are supposed to be "good examples", not checking
calloc()return isn't one.Trac: #587
Reported-By Dogbert (in Trac)Signed-off-by Gert Doering <[email protected]...>
Quoted 8 lines
--- sample/sample-plugins/defer/simple.c | 5 +++++ .../keying-material-exporter-demo/keyingmaterialexporter.c | 6 ++++++ sample/sample-plugins/log/log.c | 5 +++++ sample/sample-plugins/log/log_v3.c | 5 +++++ sample/sample-plugins/simple/simple.c | 5 +++++ 5 files changed, 26 insertions(+)
I've just glared at the code and compiled all the sample plug-ins. All looks reasonable and good.
Signature · 4 lines
kind regards, David Sommerseth OpenVPN Inc
Patch has been applied to the master, release/2.5 and release/2.4 branch.
commit a61c08a2c80d95dcc2bc30ddcb9a54a462e565ed (master) commit 5382bdbfbfb9ac26c7c75bc967af86db352b54b3 (release/2.5) commit 2b8dda69115e1e048ff685bc366705156781548c (release/2.4)
Author: Gert Doering Date: Wed Sep 9 12:48:37 2020 +0200
Handle NULL returns from calloc() in sample plugins.
Signed-off-by: Gert Doering <[email protected]...>
Acked-by: David Sommerseth <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg20922.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering