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
a149ce68
Commit
a149ce68
authored
Apr 02, 2012
by
antirez
Browse files
Prettify source code of create/verify DUMP payload.
parent
bd044659
Changes
1
Show whitespace changes
Inline
Side-by-side
src/cluster.c
View file @
a149ce68
...
@@ -1479,10 +1479,13 @@ void createDumpPayload(rio *payload, robj *o) {
...
@@ -1479,10 +1479,13 @@ void createDumpPayload(rio *payload, robj *o) {
* ----------------+---------------------+--------------+
* ----------------+---------------------+--------------+
* The SHA1 is just 8 bytes of truncated SHA1 of everything excluding itself.
* The SHA1 is just 8 bytes of truncated SHA1 of everything excluding itself.
* The 2 bytes RDB version is a little endian unsigned integer. */
* The 2 bytes RDB version is a little endian unsigned integer. */
/* RDB version */
buf
[
0
]
=
REDIS_RDB_VERSION
&
0xff
;
buf
[
0
]
=
REDIS_RDB_VERSION
&
0xff
;
buf
[
1
]
=
(
REDIS_RDB_VERSION
>>
8
)
&
0xff
;
buf
[
1
]
=
(
REDIS_RDB_VERSION
>>
8
)
&
0xff
;
payload
->
io
.
buffer
.
ptr
=
sdscatlen
(
payload
->
io
.
buffer
.
ptr
,
buf
,
2
);
payload
->
io
.
buffer
.
ptr
=
sdscatlen
(
payload
->
io
.
buffer
.
ptr
,
buf
,
2
);
/* Truncated SHA1 */
SHA1Init
(
&
ctx
);
SHA1Init
(
&
ctx
);
SHA1Update
(
&
ctx
,(
unsigned
char
*
)
payload
->
io
.
buffer
.
ptr
,
SHA1Update
(
&
ctx
,(
unsigned
char
*
)
payload
->
io
.
buffer
.
ptr
,
sdslen
(
payload
->
io
.
buffer
.
ptr
));
sdslen
(
payload
->
io
.
buffer
.
ptr
));
...
@@ -1499,10 +1502,15 @@ int verifyDumpPayload(unsigned char *p, size_t len) {
...
@@ -1499,10 +1502,15 @@ int verifyDumpPayload(unsigned char *p, size_t len) {
SHA1_CTX
ctx
;
SHA1_CTX
ctx
;
uint16_t
rdbver
;
uint16_t
rdbver
;
/* At least 2 bytes of RDB version and 8 of truncated SHA should be present. */
if
(
len
<
10
)
return
REDIS_ERR
;
if
(
len
<
10
)
return
REDIS_ERR
;
footer
=
p
+
(
len
-
10
);
footer
=
p
+
(
len
-
10
);
/* Verify RDB version */
rdbver
=
(
footer
[
1
]
<<
8
)
|
footer
[
0
];
rdbver
=
(
footer
[
1
]
<<
8
)
|
footer
[
0
];
if
(
rdbver
!=
REDIS_RDB_VERSION
)
return
REDIS_ERR
;
if
(
rdbver
!=
REDIS_RDB_VERSION
)
return
REDIS_ERR
;
/* Verify truncated SHA1 */
SHA1Init
(
&
ctx
);
SHA1Init
(
&
ctx
);
SHA1Update
(
&
ctx
,
p
,
len
-
8
);
SHA1Update
(
&
ctx
,
p
,
len
-
8
);
SHA1Final
(
hash
,
&
ctx
);
SHA1Final
(
hash
,
&
ctx
);
...
...
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