]> 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:42:22 +0000 (19:42 +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>
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 b53f13f6d34ae13ff2067df4e6280c4c717f3bfc..27275f335af2b085cf0a10213d0fa6b7dc61f8e9 100644 (file)
@@ -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;
 
index b5c1c3be4c1b85867ca2b2bd46d597e00e5b333f..a782aa9710e27cba9477fa8d722bcb5832cf9da9 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 17b83f3fecc668a04c2934e2f1899dca39b650ed..1344499745a8d2f4696d4a0fe0c6a6a7b970f919 100644 (file)
@@ -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";
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.