Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
09bb817d
Commit
09bb817d
authored
Apr 22, 2014
by
antirez
Browse files
Read bulk reply length in one pass.
See issue #1699.
parent
20c040d3
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/networking.c
View file @
09bb817d
...
@@ -997,35 +997,58 @@ int processMultibulkBuffer(redisClient *c) {
...
@@ -997,35 +997,58 @@ int processMultibulkBuffer(redisClient *c) {
while
(
c
->
multibulklen
)
{
while
(
c
->
multibulklen
)
{
/* Read bulk length if unknown */
/* Read bulk length if unknown */
if
(
c
->
bulklen
==
-
1
)
{
if
(
c
->
bulklen
==
-
1
)
{
newline
=
strchr
(
c
->
querybuf
+
pos
,
'\r'
);
char
*
p
=
c
->
querybuf
+
pos
;
if
(
newline
==
NULL
)
{
if
(
sdslen
(
c
->
querybuf
)
>
REDIS_INLINE_MAX_SIZE
)
{
/* Parse $<num>\r\n. Note that we can be certain that
addReplyError
(
c
,
"Protocol error: too big bulk count string"
);
* there is either a "\r" if the protcol is correct and
setProtocolError
(
c
,
0
);
* the bulk header is complete, or "\0" (because of sds.c API
* that gurantees null-term) if no "\r" is encountered. */
if
(
*
p
!=
'$'
)
{
if
(
*
p
==
'\0'
)
{
break
;
}
else
{
addReplyErrorFormat
(
c
,
"Protocol error: expected '$', got '%c'"
,
*
p
);
setProtocolError
(
c
,
p
-
c
->
querybuf
);
return
REDIS_ERR
;
}
}
break
;
}
p
++
;
/* Skip $ */
/* Parse the number. */
ll
=
0
;
while
(
*
p
>=
'0'
&&
*
p
<=
'9'
)
{
ll
*=
10
;
ll
+=
*
p
-
'0'
;
p
++
;
}
}
/* Buffer should also contain \n */
if
(
*
p
!=
'\r'
)
{
if
(
newline
-
(
c
->
querybuf
)
>
((
signed
)
sdslen
(
c
->
querybuf
)
-
2
))
if
(
*
p
==
'\0'
)
{
/* No complete bulk header found. */
break
;
if
(
sdslen
(
c
->
querybuf
)
>
REDIS_INLINE_MAX_SIZE
)
{
addReplyError
(
c
,
if
(
c
->
querybuf
[
pos
]
!=
'$'
)
{
"Protocol error: too big bulk count string"
);
addReplyErrorFormat
(
c
,
setProtocolError
(
c
,
p
-
c
->
querybuf
);
"Protocol error: expected '$', got '%c'"
,
return
REDIS_ERR
;
c
->
querybuf
[
pos
]);
}
setProtocolError
(
c
,
pos
);
break
;
return
REDIS_ERR
;
}
else
{
addReplyError
(
c
,
"Protocol error: invalid bulk length"
);
setProtocolError
(
c
,
p
-
c
->
querybuf
);
return
REDIS_ERR
;
}
}
}
ok
=
string2ll
(
c
->
querybuf
+
pos
+
1
,
newline
-
(
c
->
querybuf
+
pos
+
1
),
&
ll
);
if
(
*
(
p
+
1
)
==
'\0'
)
break
;
/* We need a "\n" as well. */
if
(
!
ok
||
ll
<
0
||
ll
>
512
*
1024
*
1024
)
{
p
+=
2
;
/* Skip \r\n. */
if
(
ll
<
0
||
ll
>
512
*
1024
*
1024
)
{
addReplyError
(
c
,
"Protocol error: invalid bulk length"
);
addReplyError
(
c
,
"Protocol error: invalid bulk length"
);
setProtocolError
(
c
,
pos
);
setProtocolError
(
c
,
p
-
c
->
querybuf
);
return
REDIS_ERR
;
return
REDIS_ERR
;
}
}
pos
+
=
newline
-
(
c
->
querybuf
+
pos
)
+
2
;
pos
=
p
-
c
->
querybuf
;
if
(
ll
>=
REDIS_MBULK_BIG_ARG
)
{
if
(
ll
>=
REDIS_MBULK_BIG_ARG
)
{
size_t
qblen
;
size_t
qblen
;
...
...
Write
Preview
Markdown
is supported
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