Skip to content

Commit

Permalink
fix incorrectly handle with two-words redis command
Browse files Browse the repository at this point in the history
  • Loading branch information
mazhechao committed Dec 4, 2019
1 parent 6c279eb commit 659fe8e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d

- Add support for mongodb opcode 2013 (OP_MSG). {issue}6191[6191] {pull}8594[8594]
- NFSv4: Always use opname `ILLEGAL` when failed to match request to a valid nfs operation. {pull}11503[11503]
- Redis: fix incorrectly handle with two-words redis command. {issue}14872[14872] {pull}14873[14873]

*Winlogbeat*

Expand Down
3 changes: 2 additions & 1 deletion packetbeat/protos/redis/redis_parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package redis

import (
"time"
"bytes"

"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/common/streambuf"
Expand Down Expand Up @@ -423,7 +424,7 @@ func (p *parser) parseArray(depth int, buf *streambuf.Buffer) (common.NetString,
}

// handle top-level request command
if depth == 0 && isRedisCommand(content[0]) {
if depth == 0 && (isRedisCommand(content[0]) || (count > 1 && isRedisCommand(bytes.Join(content[0:2], []byte(" "))))) {
p.message.isRequest = true
p.message.method = content[0]
if len(content) > 1 {
Expand Down
18 changes: 18 additions & 0 deletions packetbeat/protos/redis/redis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,24 @@ func TestRedisParser_ArrayRequest(t *testing.T) {
assert.Equal(t, len(arrayRequest), msg.size)
}

var arrayRequest2 = []byte("*3\r\n" +
"$6\r\n" +
"CONFIG\r\n" +
"$3\r\n" +
"GET\r\n" +
"$1\r\n" +
"*\r\n")

func TestRedisParser_ArrayRequest2(t *testing.T) {
msg, ok, complete := parse(arrayRequest2)

assert.True(t, ok)
assert.True(t, complete)
assert.True(t, msg.isRequest)
assert.Equal(t, "CONFIG GET *", string(msg.message))
assert.Equal(t, len(arrayRequest2), msg.size)
}

var arrayResponse = []byte("*4\r\n" +
"$3\r\n" +
"foo\r\n" +
Expand Down

0 comments on commit 659fe8e

Please sign in to comment.