From 9c6029225060a52d433ce7e5707736080688fe80 Mon Sep 17 00:00:00 2001 From: "Meir Shpilraien (Spielrein)" Date: Thu, 20 Jan 2022 11:10:33 +0200 Subject: [PATCH] Added functions support to redis-check-rdb (#10154) The PR added the missing verification for functions on redis-check-rdb. The verification only verifies the rdb structure and does not try to load the functions code and verify more advance checks (like compilation of the function code). --- src/rdb.c | 15 ++++++++++----- src/redis-check-rdb.c | 8 ++++++++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/rdb.c b/src/rdb.c index b13240f5b..ac5aa1f86 100644 --- a/src/rdb.c +++ b/src/rdb.c @@ -2747,7 +2747,10 @@ void rdbLoadProgressCallback(rio *r, const void *buf, size_t len) { /* Save the given functions_ctx to the rdb. * The err output parameter is optional and will be set with relevant error * message on failure, it is the caller responsibility to free the error - * message on failure. */ + * message on failure. + * + * The lib_ctx argument is also optional. If NULL is given, only verify rdb + * structure with out performing the actual functions loading. */ int rdbFunctionLoad(rio *rdb, int ver, functionsLibCtx* lib_ctx, int rdbflags, sds *err) { UNUSED(ver); sds name = NULL; @@ -2782,11 +2785,13 @@ int rdbFunctionLoad(rio *rdb, int ver, functionsLibCtx* lib_ctx, int rdbflags, s goto error; } - if (functionsCreateWithLibraryCtx(name, engine_name, desc, blob, rdbflags & RDBFLAGS_ALLOW_DUP, &error, lib_ctx) != C_OK) { - if (!error) { - error = sdsnew("Failed creating the library"); + if (lib_ctx) { + if (functionsCreateWithLibraryCtx(name, engine_name, desc, blob, rdbflags & RDBFLAGS_ALLOW_DUP, &error, lib_ctx) != C_OK) { + if (!error) { + error = sdsnew("Failed creating the library"); + } + goto error; } - goto error; } res = C_OK; diff --git a/src/redis-check-rdb.c b/src/redis-check-rdb.c index eb41b0f66..7fc798e45 100644 --- a/src/redis-check-rdb.c +++ b/src/redis-check-rdb.c @@ -303,6 +303,14 @@ int redis_check_rdb(char *rdbfilename, FILE *fp) { robj *o = rdbLoadCheckModuleValue(&rdb,name); decrRefCount(o); continue; /* Read type again. */ + } else if (type == RDB_OPCODE_FUNCTION) { + sds err = NULL; + if (rdbFunctionLoad(&rdb, rdbver, NULL, 0, &err) != C_OK) { + rdbCheckError("Failed loading library, %s", err); + sdsfree(err); + goto err; + } + continue; } else { if (!rdbIsObjectType(type)) { rdbCheckError("Invalid object type: %d", type);