Repository navigation
Store the length of the static argv when first allocated. - #1945
paddybyers wants to merge 2 commits into
Conversation
|
Is there a simple test case to add as a regression test? |
It was crashing in my application but I will try to create a standalone example. |
There was a problem hiding this comment.
@paddybyers how about extracting that line before if condition.
There was a problem hiding this comment.
I don't think so, because then it would also apply in the argv_size >= argc case, which would defeat the whole purpose ...
|
The following sequence of calls triggers the error condition: Calling this sequence in a loop invariably triggers a hard crash for me. I've added a commit to this PR that includes this as a regression test. |
|
Great. I can confirm that the test crashes the server without this patch and works fine with it. |
|
Thanks! Merged. I'll release 2.8.14 ASAP, I was planning to delay it since it contains many new small changes after merging a big PR, but it is better to fix known bugs like this instead. |
|
p.s. what about simplifying the code like that? diff --git a/src/scripting.c b/src/scripting.c
index 50e1ef1..5cd0b29 100644
--- a/src/scripting.c
+++ b/src/scripting.c
@@ -222,10 +222,7 @@ int luaRedisGenericCommand(lua_State *lua, int raise_error)
}
/* Build the arguments vector */
- if (!argv) {
- argv = zmalloc(sizeof(robj*)*argc);
- argv_size = argc;
- } else if (argv_size < argc) {
+ if (argv_size < argc) {
argv = zrealloc(argv,sizeof(robj*)*argc);
argv_size = argc;
}
@@ -403,6 +400,7 @@ cleanup:
if (c->argv != argv) {
zfree(c->argv);
argv = NULL;
+ argv_size = 0;
} |
|
Reopened in order to discuss the possible code change that simplifies the two if branches into one, however the fix and the regression test are already merged. |
without having tested it, lgtm |
|
I've tested this change and it works. Commit is here for reference: paddybyers@d0e7877 |
|
Thanks! Change committed. Closing. |
This fixes a bug introduced by this commit:
8237d88
The length of the static argv is not stored when it is first created; only when extended. On the first occasion this is relatively harmless (since the initialised length was 0), but on any subsequent "first" allocation - eg after having been cleared here: https://github.com/antirez/redis/blob/8237d88f48e0843839eb530c408686d66bcae6ab/src/scripting.c#L352
then a new allocated argv implicitly inherits the length of the last freed one. Where the new argv is smaller than the last freed one, and then later reused without extension at any length greater than its actual length, memory is overwritten.
This fixes issue #1939.
See also related issue #1943.