diff options
author | sundb <sundbcn@gmail.com> | 2021-08-06 03:42:20 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-05 22:42:20 +0300 |
commit | 8ea777a6a02cae22aeff95f054d810f30b7b69ad (patch) | |
tree | bdd956d7cd85c4e9064fe3fe9ff86c75f3d2c969 /src/rdb.h | |
parent | 39a4a44d7ddf7ca84f006d2332b6d049f05e5de4 (diff) | |
download | redis-8ea777a6a02cae22aeff95f054d810f30b7b69ad.tar.gz |
Sanitize dump payload: fix empty keys when RDB loading and restore command (#9297)
When we load rdb or restore command, if we encounter a length of 0, it will result in the creation of an empty key.
This could either be a corrupt payload, or a result of a bug (see #8453 )
This PR mainly fixes the following:
1) When restore command will return `Bad data format` error.
2) When loading RDB, we will silently discard the key.
Co-authored-by: Oran Agra <oran@redislabs.com>
Diffstat (limited to 'src/rdb.h')
-rw-r--r-- | src/rdb.h | 7 |
1 files changed, 6 insertions, 1 deletions
@@ -127,6 +127,11 @@ #define RDBFLAGS_REPLICATION (1<<1) /* Load/save for SYNC. */ #define RDBFLAGS_ALLOW_DUP (1<<2) /* Allow duplicated keys when loading.*/ +/* When rdbLoadObject() returns NULL, the err flag is + * set to hold the type of error that occurred */ +#define RDB_LOAD_ERR_EMPTY_KEY 1 /* Error of empty key */ +#define RDB_LOAD_ERR_OTHER 2 /* Any other errors */ + int rdbSaveType(rio *rdb, unsigned char type); int rdbLoadType(rio *rdb); int rdbSaveTime(rio *rdb, time_t t); @@ -145,7 +150,7 @@ void rdbRemoveTempFile(pid_t childpid, int from_signal); int rdbSave(char *filename, rdbSaveInfo *rsi); ssize_t rdbSaveObject(rio *rdb, robj *o, robj *key, int dbid); size_t rdbSavedObjectLen(robj *o, robj *key, int dbid); -robj *rdbLoadObject(int type, rio *rdb, sds key, int dbid); +robj *rdbLoadObject(int type, rio *rdb, sds key, int dbid, int *error); void backgroundSaveDoneHandler(int exitcode, int bysignal); int rdbSaveKeyValuePair(rio *rdb, robj *key, robj *val, long long expiretime,int dbid); ssize_t rdbSaveSingleModuleAux(rio *rdb, int when, moduleType *mt); |