Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #14872: fix incorrectly handle with two-words redis command #14873

Merged
merged 5 commits into from
Mar 20, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like p.message.method and p.message.path need to be computed differently as well to handle the two-word case

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will have a look and test again.

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" +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the extra whitespace here is probably what's breaking the linter... can you run mage fmt update and re-commit to make sure everything is formatted right?

Copy link
Contributor Author

@mazhechao mazhechao Dec 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get errors, would you please help me?

\# command-line-arguments
./magefile.go:153:13: undefined: "github.com/elastic/beats/dev-tools/mage".DefaultIncludeListOptions
./magefile.go:156:39: not enough arguments in call to "github.com/elastic/beats/dev-tools/mage".GenerateIncludeListGo
Error: error compiling magefiles

"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