Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Mizu
Commits
3bab8375
Unverified
Commit
3bab8375
authored
3 years ago
by
M. Mert Yıldıran
Committed by
GitHub
3 years ago
Browse files
Options
Download
Email Patches
Plain Diff
Fix the interface conversion and index out of range errors in the Redis dissector (#710)
parent
d011478a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tap/extensions/redis/read.go
+42
-19
tap/extensions/redis/read.go
with
42 additions
and
19 deletions
+42
-19
tap/extensions/redis/read.go
+
42
-
19
View file @
3bab8375
...
...
@@ -197,6 +197,12 @@ func (r *RedisInputStream) readLineBytes() ([]byte, error) {
line
:=
make
([]
byte
,
N
)
j
:=
0
for
i
:=
r
.
count
;
i
<=
N
;
i
++
{
if
i
>=
len
(
buf
)
{
return
nil
,
errors
.
New
(
"Redis buffer index mismatch."
)
}
if
i
>=
len
(
line
)
{
return
nil
,
errors
.
New
(
"Redis line index mismatch."
)
}
line
[
j
]
=
buf
[
i
]
j
++
}
...
...
@@ -295,27 +301,44 @@ func (p *RedisProtocol) Read() (packet *RedisPacket, err error) {
switch
x
.
(
type
)
{
case
[]
interface
{}
:
array
:=
x
.
([]
interface
{})
switch
array
[
0
]
.
(
type
)
{
case
[]
uint8
:
packet
.
Command
=
RedisCommand
(
strings
.
ToUpper
(
string
(
array
[
0
]
.
([]
uint8
))))
if
len
(
array
)
>
1
{
packet
.
Key
=
string
(
array
[
1
]
.
([]
uint8
))
}
if
len
(
array
)
>
2
{
packet
.
Value
=
string
(
array
[
2
]
.
([]
uint8
))
}
if
len
(
array
)
>
3
{
packet
.
Value
=
fmt
.
Sprintf
(
"[%s"
,
packet
.
Value
)
for
_
,
item
:=
range
array
[
3
:
]
{
packet
.
Value
=
fmt
.
Sprintf
(
"%s, %s"
,
packet
.
Value
,
item
.
([]
uint8
))
if
len
(
array
)
>
0
{
switch
array
[
0
]
.
(
type
)
{
case
[]
uint8
:
packet
.
Command
=
RedisCommand
(
strings
.
ToUpper
(
string
(
array
[
0
]
.
([]
uint8
))))
if
len
(
array
)
>
1
{
switch
array
[
1
]
.
(
type
)
{
case
[]
uint8
:
packet
.
Key
=
string
(
array
[
1
]
.
([]
uint8
))
case
int64
:
packet
.
Key
=
fmt
.
Sprintf
(
"%d"
,
array
[
1
]
.
(
int64
))
}
}
packet
.
Value
=
strings
.
TrimSuffix
(
packet
.
Value
,
", "
)
packet
.
Value
=
fmt
.
Sprintf
(
"%s]"
,
packet
.
Value
)
if
len
(
array
)
>
2
{
switch
array
[
2
]
.
(
type
)
{
case
[]
uint8
:
packet
.
Value
=
string
(
array
[
2
]
.
([]
uint8
))
case
int64
:
packet
.
Value
=
fmt
.
Sprintf
(
"%d"
,
array
[
2
]
.
(
int64
))
}
}
if
len
(
array
)
>
3
{
packet
.
Value
=
fmt
.
Sprintf
(
"[%s"
,
packet
.
Value
)
for
_
,
item
:=
range
array
[
3
:
]
{
switch
item
.
(
type
)
{
case
[]
uint8
:
packet
.
Value
=
fmt
.
Sprintf
(
"%s, %s"
,
packet
.
Value
,
item
.
([]
uint8
))
case
int64
:
packet
.
Value
=
fmt
.
Sprintf
(
"%s, %d"
,
packet
.
Value
,
item
.
(
int64
))
}
}
packet
.
Value
=
strings
.
TrimSuffix
(
packet
.
Value
,
", "
)
packet
.
Value
=
fmt
.
Sprintf
(
"%s]"
,
packet
.
Value
)
}
default
:
msg
:=
fmt
.
Sprintf
(
"Unrecognized element in Redis array: %v"
,
reflect
.
TypeOf
(
array
[
0
]))
err
=
errors
.
New
(
msg
)
return
}
default
:
msg
:=
fmt
.
Sprintf
(
"Unrecognized element in Redis array: %v"
,
reflect
.
TypeOf
(
array
[
0
]))
err
=
errors
.
New
(
msg
)
return
}
case
[]
uint8
:
val
:=
string
(
x
.
([]
uint8
))
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment