From 29f521de7bb80dd52c9f4dc000b7c92ba84f88d3 Mon Sep 17 00:00:00 2001 From: David Llewellyn-Jones Date: Mon, 24 Mar 2014 22:50:59 +0000 Subject: [PATCH] Added check for failed memory allocation. Set binary to output to the OpenVPNUI project. --- main.c | 34 ++++++++++++++++++++-------------- ovpnpermit.pro | 6 ++++++ ovpnpermit.pro.user | 18 +++++++++--------- 3 files changed, 35 insertions(+), 23 deletions(-) diff --git a/main.c b/main.c index 0a133b2..cce28db 100644 --- a/main.c +++ b/main.c @@ -13,23 +13,29 @@ int main (int argc, char *argv[]) { char ** newargv = malloc (sizeof(char*) * (argc + 1)); int arg; - // Transfer the arguments passed in to a new argument array - for (arg = 0; arg < argc; arg++) { - newargv[arg] = argv[arg]; - } - // Ensure the argument list is NULL terminated (for execvp) - newargv[argc] = NULL; - // Ensure the first argument matches the command - newargv[0] = command; + if (newargv != NULL) { + // Transfer the arguments passed in to a new argument array + for (arg = 0; arg < argc; arg++) { + newargv[arg] = argv[arg]; + } + // Ensure the argument list is NULL terminated (for execvp) + newargv[argc] = NULL; + // Ensure the first argument matches the command + newargv[0] = command; - // Execute the external command - //setuid (0); - execvp (command, newargv); + // Execute the external command + //setuid (0); + execvp (command, newargv); - // This part of the code shouldn't be reached - printf ("Error executing openvpn\n"); + // This part of the code shouldn't be reached unless there was a problem + fprintf (stderr, "Error executing openvpn\n"); - free (newargv); + free (newargv); + } + else { + // There was a problem with thee malloc call + fprintf (stderr, "Error allocating memory for command argument list\n"); + } return 0; } diff --git a/ovpnpermit.pro b/ovpnpermit.pro index 34f0471..bef83d2 100644 --- a/ovpnpermit.pro +++ b/ovpnpermit.pro @@ -5,3 +5,9 @@ CONFIG -= qt SOURCES += main.c +CONFIG(debug, debug|release) { + DESTDIR = ..\openvpnui\bin +} +else { + DESTDIR = ..\openvpnui\bin +} diff --git a/ovpnpermit.pro.user b/ovpnpermit.pro.user index 64ec0c7..3d476c9 100644 --- a/ovpnpermit.pro.user +++ b/ovpnpermit.pro.user @@ -1,6 +1,6 @@ - + ProjectExplorer.Project.ActiveTarget @@ -53,9 +53,9 @@ MerSDK-SailfishOS-armv7hl MerSDK-SailfishOS-armv7hl - {d509da11-0d11-4fad-8b14-f7a950fad5bf} - 0 - 2 + {d2cef3cf-98e6-437c-a097-b7f269d12d9c} + 1 + 1 0 @@ -113,7 +113,7 @@ Qt4ProjectManager.Qt4BuildConfiguration 2 - /home/flypig/Documents/Development/SailfishOS/ovpnui/build-ovpnpermit-MerSDK_SailfishOS_armv7hl-Debug + /home/flypig/Documents/Development/SailfishOS/build-ovpnpermit-MerSDK_SailfishOS_armv7hl-Debug true @@ -172,7 +172,7 @@ Qt4ProjectManager.Qt4BuildConfiguration 0 - /home/flypig/Documents/Development/SailfishOS/ovpnui/build-ovpnpermit-MerSDK_SailfishOS_armv7hl-Release + /home/flypig/Documents/Development/SailfishOS/build-ovpnpermit-MerSDK_SailfishOS_armv7hl-Release true 2 @@ -266,9 +266,9 @@ 1 - ovpnpermit (on Mer Device) + ovpnpermit (on Remote Device) - Qt4ProjectManager.MerRunConfiguration:/home/flypig/Documents/Development/SailfishOS/ovpnui/ovpnpermit/ovpnpermit.pro + Qt4ProjectManager.MerRunConfiguration:/home/flypig/Documents/Development/SailfishOS/ovpnpermit/ovpnpermit.pro ovpnpermit.pro @@ -290,7 +290,7 @@ ProjectExplorer.Project.Updater.EnvironmentId - {551e7bc8-ec93-459f-bb3a-08a2bffda2a5} + {345860fb-8510-4b40-bec6-87a56aacf929} ProjectExplorer.Project.Updater.FileVersion -- 2.25.1