From 4217a7dbab449fd3d3a244c1d92d9a6e54438773 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Wed, 6 Mar 2013 20:04:27 +0100 Subject: [PATCH] MEDIUM: config: add complete support for str2sa_range() in 'server' The server addresses are now completely parsed using str2sa_range() and the resulting protocol is checked for support for connect(). --- src/cfgparse.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/cfgparse.c b/src/cfgparse.c index b5e02cd96..cc1ae426b 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -4043,7 +4043,7 @@ stats_error_parsing: } err = invalid_char(args[1]); - if (err) { + if (err && !defsrv) { Alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n", file, linenum, *err, args[1]); err_code |= ERR_ALERT | ERR_FATAL; @@ -4053,6 +4053,8 @@ stats_error_parsing: if (!defsrv) { struct sockaddr_storage *sk; int port1, port2; + char *err_msg = NULL; + struct protocol *proto; if ((newsrv = (struct server *)calloc(1, sizeof(struct server))) == NULL) { Alert("parsing [%s:%d] : out of memory.\n", file, linenum); @@ -4082,9 +4084,19 @@ stats_error_parsing: * - IP:+N => port=+N, relative * - IP:-N => port=-N, relative */ - sk = str2sa_range(args[2], &port1, &port2, NULL, NULL); + sk = str2sa_range(args[2], &port1, &port2, &err_msg, NULL); if (!sk) { - Alert("parsing [%s:%d] : Unknown host in '%s'\n", file, linenum, args[2]); + Alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err_msg); + err_code |= ERR_ALERT | ERR_FATAL; + free(err_msg); + goto out; + } + free(err_msg); + + proto = protocol_by_family(sk->ss_family); + if (!proto || !proto->connect) { + Alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n", + file, linenum, args[0], args[1]); err_code |= ERR_ALERT | ERR_FATAL; goto out; }