Merge lp:~jan-kneschke/mysql-proxy/packet-tracking-assertions into lp:mysql-proxy/0.8

Proposed by Jan Kneschke
Status: Approved
Approved by: Leith
Approved revision: 1132
Proposed branch: lp:~jan-kneschke/mysql-proxy/packet-tracking-assertions
Merge into: lp:mysql-proxy/0.8
Diff against target: 124 lines (+29/-8)
1 file modified
src/network-mysqld-packet.c (+29/-8)
To merge this branch: bzr merge lp:~jan-kneschke/mysql-proxy/packet-tracking-assertions
Reviewer Review Type Date Requested Status
Leith (community) Approve
Review via email: mp+35834@code.launchpad.net

Description of the change

remove some g_error()s and g_assert() in the packet-tracking code to remove possibles DoS cases.

To post a comment you must log in.
Revision history for this message
Leith (mleith) wrote :

Looks good to me!

review: Approve

Unmerged revisions

1132. By <email address hidden>

replaced g_error() and g_assert() by proper error-handling and a debug-message

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/network-mysqld-packet.c'
2--- src/network-mysqld-packet.c 2010-05-10 10:31:45 +0000
3+++ src/network-mysqld-packet.c 2010-09-17 14:41:45 +0000
4@@ -281,6 +281,9 @@
5 return (udata->state == PARSE_COM_QUERY_LOCAL_INFILE_DATA) ? TRUE : FALSE;
6 }
7
8+/**
9+ * init the tracking structure for COM_STMT_PREPARE OK packets
10+ */
11 network_mysqld_com_stmt_prepare_result_t *network_mysqld_com_stmt_prepare_result_new() {
12 network_mysqld_com_stmt_prepare_result_t *udata;
13
14@@ -290,12 +293,20 @@
15 return udata;
16 }
17
18+/**
19+ * free the tracking structure for COM_STMT_PREPARE OK packets
20+ */
21 void network_mysqld_com_stmt_prepare_result_free(network_mysqld_com_stmt_prepare_result_t *udata) {
22 if (!udata) return;
23
24 g_free(udata);
25 }
26
27+/**
28+ * track if we have received all the packets of the COM_STMT_PREPARE OK packet
29+ *
30+ * @return -1 on error, 1 if all packets received, 0 if not
31+ */
32 int network_mysqld_proto_get_com_stmt_prepare_result(
33 network_packet *packet,
34 network_mysqld_com_stmt_prepare_result_t *udata) {
35@@ -305,12 +316,15 @@
36
37 err = err || network_mysqld_proto_get_int8(packet, &status);
38
39- if (udata->first_packet == 1) {
40+ if (udata->first_packet) {
41 udata->first_packet = 0;
42
43 switch (status) {
44 case MYSQLD_PACKET_OK:
45- g_assert(packet->data->len == 12 + NET_HEADER_SIZE);
46+ if (packet->data->len == 12 + NET_HEADER_SIZE) {
47+ err = -1;
48+ break;
49+ }
50
51 /* the header contains the number of EOFs we expect to see
52 * - no params -> 0
53@@ -335,7 +349,9 @@
54 is_finished = 1;
55 break;
56 default:
57- g_error("%s.%d: COM_STMT_PREPARE should either get a (OK|ERR), got %02x",
58+ err = -1;
59+
60+ g_debug("%s.%d: COM_STMT_PREPARE should either get a (OK|ERR), got %02x",
61 __FILE__, __LINE__,
62 status);
63 break;
64@@ -345,9 +361,10 @@
65 case MYSQLD_PACKET_OK:
66 case MYSQLD_PACKET_NULL:
67 case MYSQLD_PACKET_ERR:
68- g_error("%s.%d: COM_STMT_PREPARE should not be (OK|ERR|NULL), got: %02x",
69+ g_debug("%s.%d: COM_STMT_PREPARE should not be (OK|ERR|NULL), got: %02x",
70 __FILE__, __LINE__,
71 status);
72+ err = -1;
73 break;
74 case MYSQLD_PACKET_EOF:
75 if (--udata->want_eofs == 0) {
76@@ -529,9 +546,10 @@
77 is_finished = 1;
78 break;
79 default:
80- g_error("%s.%d: COM_(0x%02x) should be (ERR|OK), got %02x",
81+ g_debug("%s.%d: COM_(0x%02x) should be (ERR|OK), got %02x",
82 __FILE__, __LINE__,
83 con->parse.command, status);
84+ err = -1;
85 break;
86 }
87 break;
88@@ -554,9 +572,10 @@
89 is_finished = 1;
90 break;
91 default:
92- g_error("%s.%d: COM_(0x%02x) should be (ERR|OK), got 0x%02x",
93+ g_debug("%s.%d: COM_(0x%02x) should be (ERR|OK), got 0x%02x",
94 __FILE__, __LINE__,
95 con->parse.command, (guint8)status);
96+ err = -1;
97 break;
98 }
99 break;
100@@ -572,9 +591,10 @@
101 is_finished = 1;
102 break;
103 default:
104- g_error("%s.%d: COM_(0x%02x) should be EOF, got x%02x",
105+ g_debug("%s.%d: COM_(0x%02x) should be EOF, got x%02x",
106 __FILE__, __LINE__,
107 con->parse.command, (guint8)status);
108+ err = -1;
109 break;
110 }
111 break;
112@@ -591,10 +611,11 @@
113 break;
114 case MYSQLD_PACKET_NULL:
115 case MYSQLD_PACKET_OK:
116- g_error("%s.%d: COM_(0x%02x) should not be (OK|ERR|NULL), got: %02x",
117+ g_debug("%s.%d: COM_(0x%02x) should not be (OK|ERR|NULL), got: %02x",
118 __FILE__, __LINE__,
119 con->parse.command, status);
120
121+ err = -1;
122 break;
123 default:
124 break;

Subscribers

People subscribed via source and target branches