~eric-rnd/mysql-proxy/mysql-proxy-fixes

« back to all changes in this revision

Viewing changes to src/network-address.c

  • Committer: jan at mysql
  • Date: 2009-09-11 15:12:29 UTC
  • Revision ID: jan@mysql.com-20090911151229-s52qmmunar759irl
fixed parsing of invalid IP addresses

Show diffs side-by-side

added added

removed removed

Lines of Context:
155
155
        } else if (NULL != (s = strchr(address, ':'))) {
156
156
                gboolean ret;
157
157
                char *ip_address = g_strndup(address, s - address);
158
 
 
159
 
                guint port = strtoul(s + 1, NULL, 10);
160
 
 
161
 
                ret = network_address_set_address_ip(addr, ip_address, port);
 
158
                char *port_err = NULL;
 
159
 
 
160
                guint port = strtoul(s + 1, &port_err, 10);
 
161
 
 
162
                if (*(s + 1) == '\0') {
 
163
                        g_critical("%s: IP-address has to be in the form [<ip>][:<port>], is '%s'. No port number",
 
164
                                        G_STRLOC, address);
 
165
                        ret = -1;
 
166
                } else if (*port_err != '\0') {
 
167
                        g_critical("%s: IP-address has to be in the form [<ip>][:<port>], is '%s'. Failed to parse the port at '%s'",
 
168
                                        G_STRLOC, address, port_err);
 
169
                        ret = -1;
 
170
                } else {
 
171
                        ret = network_address_set_address_ip(addr, ip_address, port);
 
172
                }
162
173
 
163
174
                g_free(ip_address);
164
175