Merge lp:~schuster/mysql-proxy/proxy_badport_fix into lp:mysql-proxy

Proposed by Michael Schuster
Status: Merged
Merged at revision: 1087
Proposed branch: lp:~schuster/mysql-proxy/proxy_badport_fix
Merge into: lp:mysql-proxy
Diff against target: 114 lines (+24/-11)
4 files modified
plugins/proxy/proxy-plugin.c (+8/-4)
src/network-address.c (+1/-1)
src/network-backend.c (+11/-6)
tests/unit/t_network_backend.c (+4/-0)
To merge this branch: bzr merge lp:~schuster/mysql-proxy/proxy_badport_fix
Reviewer Review Type Date Requested Status
Jan Kneschke (community) Approve
Review via email: mp+25603@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Jan Kneschke (jan-kneschke) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/proxy/proxy-plugin.c'
2--- plugins/proxy/proxy-plugin.c 2010-05-10 09:50:37 +0000
3+++ plugins/proxy/proxy-plugin.c 2010-05-19 12:50:46 +0000
4@@ -2061,23 +2061,27 @@
5 /* set the plugin hooks as we want to apply them to the new connections too later */
6 network_mysqld_proxy_connection_init(con);
7
8- /* FIXME: network_socket_set_address() */
9 if (0 != network_address_set_address(listen_sock->dst, config->address)) {
10 return -1;
11 }
12
13- /* FIXME: network_socket_bind() */
14 if (0 != network_socket_bind(listen_sock)) {
15 return -1;
16 }
17 g_message("proxy listening on port %s", config->address);
18
19 for (i = 0; config->backend_addresses && config->backend_addresses[i]; i++) {
20- network_backends_add(g->backends, config->backend_addresses[i], BACKEND_TYPE_RW);
21+ if (-1 == network_backends_add(g->backends, config->backend_addresses[i],
22+ BACKEND_TYPE_RW)) {
23+ return -1;
24+ }
25 }
26
27 for (i = 0; config->read_only_backend_addresses && config->read_only_backend_addresses[i]; i++) {
28- network_backends_add(g->backends, config->read_only_backend_addresses[i], BACKEND_TYPE_RO);
29+ if (-1 == network_backends_add(g->backends,
30+ config->read_only_backend_addresses[i], BACKEND_TYPE_RO)) {
31+ return -1;
32+ }
33 }
34
35 /* load the script and setup the global tables */
36
37=== modified file 'src/network-address.c'
38--- src/network-address.c 2010-05-12 15:38:56 +0000
39+++ src/network-address.c 2010-05-19 12:50:46 +0000
40@@ -238,7 +238,7 @@
41 return network_address_set_address_un(addr, address);
42
43 if (NULL != (s = strchr(address, ':'))) {
44- gboolean ret;
45+ gint ret;
46 char *ip_address = g_strndup(address, s - address); /* may be NULL for strdup(..., 0) */
47 char *port_err = NULL;
48
49
50=== modified file 'src/network-backend.c'
51--- src/network-backend.c 2010-04-06 14:26:51 +0000
52+++ src/network-backend.c 2010-05-19 12:50:46 +0000
53@@ -98,10 +98,13 @@
54 g_free(bs);
55 }
56
57+/*
58+ * FIXME: 1) remove _set_address, make this function callable with result of same
59+ * 2) differentiate between reasons for "we didn't add" (now -1 in all cases)
60+ */
61 int network_backends_add(network_backends_t *bs, /* const */ gchar *address, backend_type_t type) {
62 network_backend_t *new_backend;
63 guint i;
64- gboolean is_known = FALSE;
65
66 new_backend = network_backend_new();
67 new_backend->type = type;
68@@ -119,18 +122,20 @@
69 if (strleq(S(old_backend->addr->name), S(new_backend->addr->name))) {
70 network_backend_free(new_backend);
71
72- is_known = TRUE;
73- break;
74+ g_mutex_unlock(bs->backends_mutex);
75+ g_critical("backend %s is already known!", address);
76+ return -1;
77 }
78 }
79
80
81- if (!is_known) g_ptr_array_add(bs->backends, new_backend);
82+ g_ptr_array_add(bs->backends, new_backend);
83 g_mutex_unlock(bs->backends_mutex);
84
85- if (!is_known) g_message("added %s backend: %s", (type == BACKEND_TYPE_RW) ? "read/write" : "read-only", address);
86+ g_message("added %s backend: %s", (type == BACKEND_TYPE_RW) ?
87+ "read/write" : "read-only", address);
88
89- return is_known ? -1 : 0;
90+ return 0;
91 }
92
93 /**
94
95=== modified file 'tests/unit/t_network_backend.c'
96--- tests/unit/t_network_backend.c 2010-04-06 14:26:51 +0000
97+++ tests/unit/t_network_backend.c 2010-05-19 12:50:46 +0000
98@@ -51,6 +51,7 @@
99 void t_network_backends_add() {
100 network_backends_t *backends;
101
102+ g_log_set_always_fatal(G_LOG_FATAL_MASK);
103 backends = network_backends_new();
104 g_assert(backends);
105
106@@ -71,6 +72,9 @@
107
108 g_assert_cmpint(network_backends_count(backends), ==, 1);
109
110+ /* make sure bad port numbers also fail */
111+ g_assert_cmpint(network_backends_add(backends, "127.0.0.1:113306", BACKEND_TYPE_RW), ==, -1);
112+
113 network_backends_free(backends);
114 }
115

Subscribers

People subscribed via source and target branches