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
4c9c9d72
Commit
4c9c9d72
authored
May 18, 2016
by
Salvatore Sanfilippo
Browse files
Merge pull request #3221 from oranagra/bitfield_fix
fix crash in BITFIELD GET when key is integer encoded
parents
078f4612
77a91442
Changes
1
Show whitespace changes
Inline
Side-by-side
src/bitops.c
View file @
4c9c9d72
...
@@ -1035,16 +1035,28 @@ void bitfieldCommand(client *c) {
...
@@ -1035,16 +1035,28 @@ void bitfieldCommand(client *c) {
changes
++
;
changes
++
;
}
else
{
}
else
{
/* GET */
/* GET */
o
=
lookupKeyRead
(
c
->
db
,
c
->
argv
[
1
]);
size_t
olen
=
(
o
==
NULL
)
?
0
:
sdslen
(
o
->
ptr
);
unsigned
char
buf
[
9
];
unsigned
char
buf
[
9
];
size_t
olen
=
0
;
unsigned
char
*
src
=
NULL
;
char
llbuf
[
32
];
o
=
lookupKeyRead
(
c
->
db
,
c
->
argv
[
1
]);
/* Set the 'p' pointer to the string, that can be just a stack allocated
* array if our string was integer encoded. */
if
(
o
&&
o
->
encoding
==
OBJ_ENCODING_INT
)
{
src
=
(
unsigned
char
*
)
llbuf
;
olen
=
ll2string
(
llbuf
,
sizeof
(
llbuf
),(
long
)
o
->
ptr
);
}
else
if
(
o
)
{
src
=
(
unsigned
char
*
)
o
->
ptr
;
olen
=
sdslen
(
o
->
ptr
);
}
/* For GET we use a trick: before executing the operation
/* For GET we use a trick: before executing the operation
* copy up to 9 bytes to a local buffer, so that we can easily
* copy up to 9 bytes to a local buffer, so that we can easily
* execute up to 64 bit operations that are at actual string
* execute up to 64 bit operations that are at actual string
* object boundaries. */
* object boundaries. */
memset
(
buf
,
0
,
9
);
memset
(
buf
,
0
,
9
);
unsigned
char
*
src
=
o
?
o
->
ptr
:
NULL
;
int
i
;
int
i
;
size_t
byte
=
thisop
->
offset
>>
3
;
size_t
byte
=
thisop
->
offset
>>
3
;
for
(
i
=
0
;
i
<
9
;
i
++
)
{
for
(
i
=
0
;
i
<
9
;
i
++
)
{
...
...
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