]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
Handle NULL returns from calloc() in sample plugins.
authorGert Doering <gert@greenie.muc.de>
Wed, 9 Sep 2020 10:48:37 +0000 (12:48 +0200)
committerGert Doering <gert@greenie.muc.de>
Fri, 11 Sep 2020 17:43:16 +0000 (19:43 +0200)
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 <gert@greenie.muc.de>
Acked-by: David Sommerseth <davids@openvpn.net>
Message-Id: <20200909104837.6123-1-gert@greenie.muc.de>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg20922.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit a61c08a2c80d95dcc2bc30ddcb9a54a462e565ed)

sample/sample-plugins/defer/simple.c
sample/sample-plugins/keying-material-exporter-demo/keyingmaterialexporter.c
sample/sample-plugins/log/log.c
sample/sample-plugins/log/log_v3.c
sample/sample-plugins/simple/simple.c

index d18695b59d6966e5cc84a19e176ea9ec18d0b452..64338b4aace16e230bd2beb1bcd310c8d5143602 100644 (file)
@@ -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);
index 5d3ca14ded73b93908b89d5b4eefb3eb50f95249..8e34a3ed5e3d7ee24e8b118ecdb19b968f12d990 100644 (file)
@@ -94,6 +94,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;
 
index ecf62c0e653c8ec852ab641e75363747b795c1af..1f419e04ca65608e47087c4b06143a6226f393a8 100644 (file)
@@ -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.
index c972951deec8b9d0ee7308813a629e62203f0603..3da3b4750870a9bcf7fee2a1dce5287f7afd45df 100644 (file)
@@ -115,6 +115,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";
index 950c547e22c1d44c59812eb90606fbdb52981021..60cfea4f1fa3e0edf311c54d9cd69a12c943f206 100644 (file)
@@ -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.