X-Git-Url: https://www.flypig.org.uk/git/?a=blobdiff_plain;f=main.c;h=cce28dbdfd57312abf5fda6e2d9472fd58872e3a;hb=29f521de7bb80dd52c9f4dc000b7c92ba84f88d3;hp=0a133b26db9b205d7346bd58ef2d80980bdf8cd5;hpb=8e30030fad3a540cab58c764ce35a857018c12de;p=ovpnpermit.git 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; }