changeset 2282:ff4b358ef3bc

Fix/improve IPv6 listening interface IP address support in mapsearch.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 09 Apr 2020 08:22:41 +0300
parents 943a3e20f1e8
children 30d5f56ed373
files mapsearch.c
diffstat 1 files changed, 15 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/mapsearch.c	Fri Apr 03 00:02:42 2020 +0300
+++ b/mapsearch.c	Thu Apr 09 08:22:41 2020 +0300
@@ -51,7 +51,6 @@
     char *vhostname;         // Vhost name
     int port;                // Port number
 
-    BOOL useIPv6;
     BOOL useSSL;             // Use SSL/TLS?
     char *sslCertFile,       // Certificate file
          *sslKeyFile,        // Key file
@@ -130,11 +129,10 @@
     fprintf(stdout,
         "\n"
         "Listening interface(s) are specified with following syntax:\n"
-        "-l \"[@]<interface/IP/host>:<port>[=<SSL/TLS spec>]\"\n"
+        "-l \"<interface/IP/host>:<port>[=<SSL/TLS spec>]\"\n"
         "\n"
-        "IPv6 addresses should be specified with the square bracket notation.\n"
-        "To force IPv6, use IPv6 address [] or prefix spec with @. In order to\n"
-        "listen to all interfaces, you can specify an asterisk (*) as host. Example:\n"
+        "IPv6 addresses should be specified with the square bracket notation [].\n"
+        "To listen to all interfaces, you can specify an asterisk (*) as host:\n"
         "\n"
         "-l *:3491 -l *:3492=<vhostname for SNI>:<ssl_cert_file.crt>:<ssl_key_file.key>:<ca_file.crt>\n"
         "\n"
@@ -316,12 +314,6 @@
         goto out;
 
     interface = fmt;
-    if (*interface == '@')
-    {
-        interface++;
-        ctx->useIPv6 = TRUE;
-    }
-
     if (*interface == '[')
     {
         // IPv6 IP address is handled in a special case
@@ -332,7 +324,13 @@
             goto out;
         }
         *end++ = 0;
-        ctx->useIPv6 = TRUE;
+
+        for (size_t n = 0; interface[n]; n++)
+        if (!isxdigit(interface[n]) && interface[n] != ':')
+        {
+            mapERR("Invalid IPv6 IP address '%s'.\n", interface);
+            goto out;
+        }
     }
     else
     {
@@ -366,7 +364,11 @@
         mapERR("Missing listening port in '%s'.\n", cfmt);
         goto out;
     }
-    ctx->port = atoi(port);
+    if ((ctx->port = atoi(port)) < 1)
+    {
+        mapERR("Invalid listening port %d in '%s'.\n", ctx->port, cfmt);
+        goto out;
+    }
 
     // Parse the SSL/TLS spec, if any
     if (flags != NULL)