Skip to content

Commit

Permalink
Packetbeat, mysql proto, add \r to trim SQLs captured from app runnin… (
Browse files Browse the repository at this point in the history
elastic#5572)

* Packetbeat, mysql proto, add \r to trim SQLs captured from app running on Windows server. Otherwise method extracted including \r, which is problem. e.g. "SELECT\r\n\t1"

* Packetbeat, test case for windows lineending

* Packetbeat, changelog for windows lineending
  • Loading branch information
timesking authored and adriansr committed Apr 6, 2018
1 parent 6c2070c commit e2093cc
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ https://github.com/elastic/beats/compare/v5.6.8...5.6[Check the HEAD diff]

- Fix http status phrase parsing not allow spaces. {pull}5312[5312]
- Fix http parse to allow to parse get request with space in the URI. {pull}5495[5495]
- Fix mysql SQL parser to trim `\r` from Windows Server `SELECT\r\n\t1`. {pull}5572[5572]

*Winlogbeat*

Expand Down
4 changes: 2 additions & 2 deletions packetbeat/protos/mysql/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -607,8 +607,8 @@ func (mysql *mysqlPlugin) receivedMysqlRequest(msg *mysqlMessage) {

// Extract the method, by simply taking the first word and
// making it upper case.
query := strings.Trim(msg.query, " \n\t")
index := strings.IndexAny(query, " \n\t")
query := strings.Trim(msg.query, " \r\n\t")
index := strings.IndexAny(query, " \r\n\t")
var method string
if index > 0 {
method = strings.ToUpper(query[:index])
Expand Down
Binary file not shown.
24 changes: 24 additions & 0 deletions packetbeat/tests/system/test_0064_mysql_windows_lineending.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from packetbeat import BaseTest

"""
Tests for MySQL messages with Windows line ending \\r\\n.
"""


class Test(BaseTest):

def test_rn(self):
"""
Should get method "SELECT" instead of "SELECT\\r"
"""
self.render_config_template(
mysql_ports=[3306],
)
self.run_packetbeat(pcap="mysql_windows_lineending.pcap")

objs = self.read_output()
assert len(objs) == 1
o = objs[0]

assert o["status"] == "OK"
assert o["method"] == "SELECT"

0 comments on commit e2093cc

Please sign in to comment.