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

Conversation

mazhechao
Copy link
Contributor

@mazhechao mazhechao commented Dec 1, 2019

Fixes #14872

@mazhechao mazhechao requested a review from a team as a code owner December 1, 2019 13:30
@elasticmachine
Copy link
Collaborator

Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually?

1 similar comment
@elasticmachine
Copy link
Collaborator

Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually?

Copy link
Contributor

@adriansr adriansr left a comment

Choose a reason for hiding this comment

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

Thanks @mazhechao for reporting AND fixing this 😄

Can you add a entry to CHANGELOG.next.asciidoc too?

@@ -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]) || isRedisCommand(bytes.Join(content[0:2], []byte(" ")))) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this needs a check in the (unlikely?) case that count < 2

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would you explain more details about what to check? I just don't understand what do you mean.

Copy link
Contributor

Choose a reason for hiding this comment

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

I mean accessing content[0:2] can fail if len(content) is 1, so you can write

 	if depth == 0 && (isRedisCommand(content[0]) || (count > 1 && isRedisCommand(bytes.Join(content[0:2], []byte(" "))))) { 

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right. I get it.

@adriansr adriansr self-assigned this Dec 2, 2019
@mazhechao
Copy link
Contributor Author

@adriansr Would you please review again?

@@ -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.

@@ -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

@mazhechao
Copy link
Contributor Author

@adriansr @faec Would you please review my commits again?
And I don't know how to solve the lint problem, when I run mage fmt update, I get some errors

\# 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 

@elasticmachine
Copy link
Collaborator

Pinging @elastic/siem (Team:SIEM)

@adriansr
Copy link
Contributor

jenkins, test this

@adriansr adriansr requested a review from faec March 20, 2020 14:39
Copy link
Contributor

@faec faec left a comment

Choose a reason for hiding this comment

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

Thank you!

@adriansr adriansr merged commit 30a5687 into elastic:master Mar 20, 2020
adriansr pushed a commit to adriansr/beats that referenced this pull request Mar 20, 2020
elastic#14873)

Updated redis protocol decoder to support two-word commands.

Fixes elastic#14872

(cherry picked from commit 30a5687)
adriansr added a commit that referenced this pull request Mar 20, 2020
…) (#17153)

Updated redis protocol decoder to support two-word commands.

Fixes #14872

(cherry picked from commit 30a5687)

Co-authored-by: shawshank <mazhechao@gmail.com>
@mazhechao
Copy link
Contributor Author

Is this released in v7.7.0, I can't find in the release notes. @adriansr

@adriansr
Copy link
Contributor

adriansr commented Jul 9, 2020

@mazhechao I don't know why it's not in the release notes, but it made it to 7.7.0

@mazhechao
Copy link
Contributor Author

I think it's better to mention this fix in the release notes. @adriansr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Packetbeat cannot capture redis command CONFIG GET
6 participants