Skip to content

Commit

Permalink
Fixed handling of responses larger than 100K.
Browse files Browse the repository at this point in the history
We have a limitation of how much we process per mysql response
(MAX_PAYLOAD_SIZE) but there was a bug in which we were referring to
the trimmed size instead of the real size when eating data from the buffer.
  • Loading branch information
Tudor Golubenco committed Jun 5, 2015
1 parent 12a8523 commit 2a02653
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion protos/mysql/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func (mysql *Mysql) Init(test_mode bool, results chan common.MapStr) error {
}

func (stream *MysqlStream) PrepareForNewMessage() {
stream.data = stream.data[stream.message.end:]
stream.data = stream.data[stream.parseOffset:]
stream.parseState = mysqlStateStart
stream.parseOffset = 0
stream.isClient = false
Expand Down Expand Up @@ -458,6 +458,7 @@ func (mysql *Mysql) Parse(pkt *protos.Packet, tcptuple *common.TcpTuple,
}

ok, complete := mysqlMessageParser(priv.Data[dir])
//logp.Debug("mysqldetailed", "mysqlMessageParser returned ok=%b complete=%b", ok, complete)
if !ok {
// drop this tcp stream. Will retry parsing with the next
// segment in it
Expand Down
Binary file added tests/pcaps/mysql_long.pcap
Binary file not shown.
16 changes: 16 additions & 0 deletions tests/test_0017_mysql_long_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,19 @@ def test_larger_max_rows(self):

lines = res["response"].strip().split("\n")
assert len(lines) == 16 # 15 plus header

def test_larger_than_100k(self):
"""
Should work for MySQL messages larger than 100k bytes.
"""
self.render_config_template(
mysql_ports=[3306],
mysql_send_response=True
)
self.run_packetbeat(pcap="mysql_long.pcap",
debug_selectors=["mysqldetailed"])

objs = self.read_output()
assert len(objs) == 1
res = objs[0]
assert res["mysql.num_rows"] == 400

0 comments on commit 2a02653

Please sign in to comment.