Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
b12d2f65
"tests/vscode:/vscode.git/clone" did not exist on "5afe1e37c7f04224831d6e0e34579e4ce496d006"
Commit
b12d2f65
authored
Nov 04, 2019
by
Loris Cro
Browse files
fix unreported overflow in autogerenared stream IDs
parent
3f14bfd8
Changes
2
Show whitespace changes
Inline
Side-by-side
src/t_stream.c
View file @
b12d2f65
...
@@ -173,9 +173,19 @@ int streamCompareID(streamID *a, streamID *b) {
...
@@ -173,9 +173,19 @@ int streamCompareID(streamID *a, streamID *b) {
* C_ERR if an ID was given via 'use_id', but adding it failed since the
* C_ERR if an ID was given via 'use_id', but adding it failed since the
* current top ID is greater or equal. */
* current top ID is greater or equal. */
int
streamAppendItem
(
stream
*
s
,
robj
**
argv
,
int64_t
numfields
,
streamID
*
added_id
,
streamID
*
use_id
)
{
int
streamAppendItem
(
stream
*
s
,
robj
**
argv
,
int64_t
numfields
,
streamID
*
added_id
,
streamID
*
use_id
)
{
/* If an ID was given, check that it's greater than the last entry ID
* or return an error. */
/* Generate the new entry ID. */
if
(
use_id
&&
streamCompareID
(
use_id
,
&
s
->
last_id
)
<=
0
)
return
C_ERR
;
streamID
id
;
if
(
use_id
)
id
=
*
use_id
;
else
streamNextID
(
&
s
->
last_id
,
&
id
);
/* Check that the new ID is greater than the last entry ID
* or return an error. Automatically generated IDs might
* overflow (and wrap-around) when incrementing the sequence
part. */
if
(
streamCompareID
(
&
id
,
&
s
->
last_id
)
<=
0
)
return
C_ERR
;
/* Add the new entry. */
/* Add the new entry. */
raxIterator
ri
;
raxIterator
ri
;
...
@@ -192,13 +202,6 @@ int streamAppendItem(stream *s, robj **argv, int64_t numfields, streamID *added_
...
@@ -192,13 +202,6 @@ int streamAppendItem(stream *s, robj **argv, int64_t numfields, streamID *added_
}
}
raxStop
(
&
ri
);
raxStop
(
&
ri
);
/* Generate the new entry ID. */
streamID
id
;
if
(
use_id
)
id
=
*
use_id
;
else
streamNextID
(
&
s
->
last_id
,
&
id
);
/* We have to add the key into the radix tree in lexicographic order,
/* We have to add the key into the radix tree in lexicographic order,
* to do so we consider the ID as a single 128 bit number written in
* to do so we consider the ID as a single 128 bit number written in
* big endian, so that the most significant bytes are the first ones. */
* big endian, so that the most significant bytes are the first ones. */
...
...
tests/unit/type/stream.tcl
View file @
b12d2f65
...
@@ -79,6 +79,12 @@ start_server {
...
@@ -79,6 +79,12 @@ start_server {
assert
{[
streamCompareID $id2 $id3
]
== -1
}
assert
{[
streamCompareID $id2 $id3
]
== -1
}
}
}
test
{
XADD IDs correctly report an error when overflowing
}
{
r DEL mystream
r xadd mystream 18446744073709551615-18446744073709551615 a b
assert_error ERR*
{
r xadd mystream * c d
}
}
test
{
XADD with MAXLEN option
}
{
test
{
XADD with MAXLEN option
}
{
r DEL mystream
r DEL mystream
for
{
set j 0
}
{
$j
< 1000
}
{
incr j
}
{
for
{
set j 0
}
{
$j
< 1000
}
{
incr j
}
{
...
...
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