Don't try to use kill() on Windows.
[tinc] / src / tincctl.c
index 9f9df6f..5067ded 100644 (file)
@@ -1,6 +1,6 @@
 /*
     tincctl.c -- Controlling a running tincd
-    Copyright (C) 2007-2016 Guus Sliepen <guus@tinc-vpn.org>
+    Copyright (C) 2007-2017 Guus Sliepen <guus@tinc-vpn.org>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -446,11 +446,13 @@ static bool rsa_keygen(int bits, bool ask) {
        // Make sure the key size is a multiple of 8 bits.
        bits &= ~0x7;
 
-       // Force them to be between 1024 and 8192 bits long.
-       if(bits < 1024)
-               bits = 1024;
-       if(bits > 8192)
-               bits = 8192;
+       // Make sure that a valid key size is used.
+       if(bits < 1024 || bits > 8192) {
+               fprintf(stderr, "Invalid key size %d specified! It should be between 1024 and 8192 bits.\n", bits);
+               return false;
+       } else if(bits < 2048) {
+               fprintf(stderr, "WARNING: generating a weak %d bits RSA key! 2048 or more bits are recommended.\n", bits);
+       }
 
        fprintf(stderr, "Generating %d bits keys:\n", bits);
 
@@ -560,6 +562,7 @@ bool sendline(int fd, char *format, ...) {
 
        va_start(ap, format);
        blen = vsnprintf(buffer, sizeof buffer, format, ap);
+       buffer[sizeof buffer - 1] = 0;
        va_end(ap);
 
        if(blen < 1 || blen >= sizeof buffer)
@@ -718,6 +721,8 @@ bool connect_tincd(bool verbose) {
        }
 
        fclose(f);
+
+#ifndef HAVE_MINGW
        if ((pid == 0) || (kill(pid, 0) && (errno == ESRCH))) {
                fprintf(stderr, "Could not find tincd running at pid %d\n", pid);
                /* clean up the stale socket and pid file */
@@ -726,7 +731,6 @@ bool connect_tincd(bool verbose) {
                return false;
        }
 
-#ifndef HAVE_MINGW
        struct sockaddr_un sa;
        sa.sun_family = AF_UNIX;
        strncpy(sa.sun_path, unixsocketname, sizeof sa.sun_path);
@@ -885,7 +889,7 @@ static int cmd_start(int argc, char *argv[]) {
 
        if(!pid) {
                close(pfd[0]);
-               char buf[100] = "";
+               char buf[100];
                snprintf(buf, sizeof buf, "%d", pfd[1]);
                setenv("TINC_UMBILICAL", buf, true);
                exit(execvp(c, nargv));
@@ -2520,6 +2524,7 @@ static int cmd_verify(int argc, char *argv[]) {
        char *newline = memchr(data, '\n', len);
        if(!newline || (newline - data > MAX_STRING_SIZE - 1)) {
                fprintf(stderr, "Invalid input\n");
+               free(data);
                return 1;
        }
 
@@ -2532,11 +2537,13 @@ static int cmd_verify(int argc, char *argv[]) {
 
        if(sscanf(data, "Signature = %s %ld %s", signer, &t, sig) != 3 || strlen(sig) != 86 || !t || !check_id(signer)) {
                fprintf(stderr, "Invalid input\n");
+               free(data);
                return 1;
        }
 
        if(node && strcmp(node, signer)) {
                fprintf(stderr, "Signature is not made by %s\n", node);
+               free(data);
                return 1;
        }
 
@@ -2830,8 +2837,10 @@ static int cmd_shell(int argc, char *argv[]) {
                if(nargc == argc)
                        continue;
 
-               if(!strcasecmp(nargv[argc], "exit") || !strcasecmp(nargv[argc], "quit"))
+               if(!strcasecmp(nargv[argc], "exit") || !strcasecmp(nargv[argc], "quit")) {
+                       free(nargv);
                        return result;
+               }
 
                bool found = false;