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
e697153d
Commit
e697153d
authored
Jul 01, 2016
by
antirez
Browse files
In Redis RDB check: log decompression errors.
parent
df3c69e8
Changes
2
Show whitespace changes
Inline
Side-by-side
src/rdb.c
View file @
e697153d
...
@@ -45,6 +45,7 @@
...
@@ -45,6 +45,7 @@
extern
int
rdbCheckMode
;
extern
int
rdbCheckMode
;
void
rdbCheckError
(
const
char
*
fmt
,
...);
void
rdbCheckError
(
const
char
*
fmt
,
...);
void
rdbCheckSetError
(
const
char
*
fmt
,
...);
void
rdbCheckThenExit
(
char
*
reason
,
int
where
)
{
void
rdbCheckThenExit
(
char
*
reason
,
int
where
)
{
if
(
!
rdbCheckMode
)
{
if
(
!
rdbCheckMode
)
{
...
@@ -341,7 +342,10 @@ void *rdbLoadLzfStringObject(rio *rdb, int flags, size_t *lenptr) {
...
@@ -341,7 +342,10 @@ void *rdbLoadLzfStringObject(rio *rdb, int flags, size_t *lenptr) {
/* Load the compressed representation and uncompress it to target. */
/* Load the compressed representation and uncompress it to target. */
if
(
rioRead
(
rdb
,
c
,
clen
)
==
0
)
goto
err
;
if
(
rioRead
(
rdb
,
c
,
clen
)
==
0
)
goto
err
;
if
(
lzf_decompress
(
c
,
clen
,
val
,
len
)
==
0
)
goto
err
;
if
(
lzf_decompress
(
c
,
clen
,
val
,
len
)
==
0
)
{
if
(
rdbCheckMode
)
rdbCheckSetError
(
"Invalid LZF compressed string"
);
goto
err
;
}
zfree
(
c
);
zfree
(
c
);
if
(
plain
||
sds
)
{
if
(
plain
||
sds
)
{
...
...
src/redis-check-rdb.c
View file @
e697153d
...
@@ -45,6 +45,8 @@ struct {
...
@@ -45,6 +45,8 @@ struct {
unsigned
long
expires
;
/* Number of keys with an expire. */
unsigned
long
expires
;
/* Number of keys with an expire. */
unsigned
long
already_expired
;
/* Number of keys already expired. */
unsigned
long
already_expired
;
/* Number of keys already expired. */
int
doing
;
/* The state while reading the RDB. */
int
doing
;
/* The state while reading the RDB. */
int
error_set
;
/* True if error is populated. */
char
error
[
1024
];
}
rdbstate
;
}
rdbstate
;
/* At every loading step try to remember what we were about to do, so that
/* At every loading step try to remember what we were about to do, so that
...
@@ -135,6 +137,17 @@ void rdbCheckInfo(const char *fmt, ...) {
...
@@ -135,6 +137,17 @@ void rdbCheckInfo(const char *fmt, ...) {
rdbstate
.
rio
->
processed_bytes
:
0
),
msg
);
rdbstate
.
rio
->
processed_bytes
:
0
),
msg
);
}
}
/* Used inside rdb.c in order to log specific errors happening inside
* the RDB loading internals. */
void
rdbCheckSetError
(
const
char
*
fmt
,
...)
{
va_list
ap
;
va_start
(
ap
,
fmt
);
vsnprintf
(
rdbstate
.
error
,
sizeof
(
rdbstate
.
error
),
fmt
,
ap
);
va_end
(
ap
);
rdbstate
.
error_set
=
1
;
}
/* During RDB check we setup a special signal handler for memory violations
/* During RDB check we setup a special signal handler for memory violations
* and similar conditions, so that we can log the offending part of the RDB
* and similar conditions, so that we can log the offending part of the RDB
* if the crash is due to broken content. */
* if the crash is due to broken content. */
...
@@ -300,7 +313,11 @@ int redis_check_rdb(char *rdbfilename) {
...
@@ -300,7 +313,11 @@ int redis_check_rdb(char *rdbfilename) {
return
0
;
return
0
;
eoferr:
/* unexpected end of file is handled here with a fatal exit */
eoferr:
/* unexpected end of file is handled here with a fatal exit */
if
(
rdbstate
.
error_set
)
{
rdbCheckError
(
rdbstate
.
error
);
}
else
{
rdbCheckError
(
"Unexpected EOF reading RDB file"
);
rdbCheckError
(
"Unexpected EOF reading RDB file"
);
}
return
1
;
return
1
;
}
}
...
...
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