]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: config: use str2sa_range() to parse peers addresses
authorWilly Tarreau <w@1wt.eu>
Wed, 20 Feb 2013 18:20:59 +0000 (19:20 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 20 Feb 2013 18:23:44 +0000 (19:23 +0100)
Similarly to previous changes, use str2sa_range() so that we can
detect invalid addresses or port configurations in peers.

src/cfgparse.c

index 34d29e426a1d11b51e83385da345b0e04ed865cb..1a2fc8ab644835fd522266fcd6d11219e6272326 100644 (file)
@@ -1480,9 +1480,8 @@ int cfg_parse_peers(const char *file, int linenum, char **args, int kwm)
                curpeers->id = strdup(args[1]);
        }
        else if (strcmp(args[0], "peer") == 0) { /* peer definition */
-               char *rport, *raddr;
-               short realport = 0;
                struct sockaddr_storage *sk;
+               int port1, port2;
                char *err_msg = NULL;
 
                if (!*args[2]) {
@@ -1517,26 +1516,27 @@ int cfg_parse_peers(const char *file, int linenum, char **args, int kwm)
                newpeer->last_change = now.tv_sec;
                newpeer->id = strdup(args[1]);
 
-               raddr = strdup(args[2]);
-               rport = strrchr(raddr, ':');
-               if (rport) {
-                       *rport++ = 0;
-                       realport = atol(rport);
+               sk = str2sa_range(args[2], &port1, &port2);
+               if (!sk) {
+                       Alert("parsing [%s:%d] : '%s %s' : unknown host in '%s'\n", file, linenum, args[0], args[1], args[2]);
+                       err_code |= ERR_ALERT | ERR_FATAL;
+                       goto out;
                }
-               if (!realport) {
-                       Alert("parsing [%s:%d] : Missing or invalid port in '%s'\n", file, linenum, args[2]);
+
+               if (port1 != port2) {
+                       Alert("parsing [%s:%d] : '%s %s' : port ranges and offsets are not allowed in '%s'\n",
+                             file, linenum, args[0], args[1], args[2]);
                        err_code |= ERR_ALERT | ERR_FATAL;
-                       free(raddr);
                        goto out;
                }
 
-               sk = str2ip(raddr);
-               free(raddr);
-               if (!sk) {
-                       Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[2]);
+               if (!port1) {
+                       Alert("parsing [%s:%d] : '%s %s' : missing or invalid port in '%s'\n",
+                             file, linenum, args[0], args[1], args[2]);
                        err_code |= ERR_ALERT | ERR_FATAL;
                        goto out;
                }
+
                newpeer->addr = *sk;
                newpeer->proto = protocol_by_family(newpeer->addr.ss_family);
                newpeer->xprt  = &raw_sock;
@@ -1549,8 +1549,6 @@ int cfg_parse_peers(const char *file, int linenum, char **args, int kwm)
                        goto out;
                }
 
-               set_host_port(&newpeer->addr, realport);
-
                if (strcmp(newpeer->id, localpeer) == 0) {
                        /* Current is local peer, it define a frontend */
                        newpeer->local = 1;