-
Notifications
You must be signed in to change notification settings - Fork 0
Clean up lookahead-related code #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: coderabbit_full_base_clean_up_lookahead-related_code_pr3
Are you sure you want to change the base?
Changes from all commits
e0a9016
2351487
d768d7b
8a3fe63
4689ac1
ec682c6
cfae119
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -426,27 +426,16 @@ int getKeySlot(sds key) { | |
| } | ||
|
|
||
| /* Return the slot of the key in the command. | ||
| * GETSLOT_NOKEYS if no keys, GETSLOT_CROSSSLOT if cross slot, otherwise the slot number. */ | ||
| * INVALID_CLUSTER_SLOT if no keys, CLUSTER_CROSSSLOT if cross slot, otherwise the slot number. */ | ||
| int getSlotFromCommand(struct redisCommand *cmd, robj **argv, int argc) { | ||
| int slot = GETSLOT_NOKEYS; | ||
| if (!cmd || !server.cluster_enabled) return slot; | ||
| if (!cmd || !server.cluster_enabled) return INVALID_CLUSTER_SLOT; | ||
|
|
||
| /* Get the keys from the command */ | ||
| getKeysResult result = GETKEYS_RESULT_INIT; | ||
| int numkeys = getKeysFromCommand(cmd, argv, argc, &result); | ||
| keyReference *keyindex = result.keys; | ||
|
|
||
| /* Get slot of each key and check if they are all the same */ | ||
| for (int j = 0; j < numkeys; j++) { | ||
| robj *thiskey = argv[keyindex[j].pos]; | ||
| int thisslot = keyHashSlot((char*)thiskey->ptr, sdslen(thiskey->ptr)); | ||
| if (slot == GETSLOT_NOKEYS) { | ||
| slot = thisslot; | ||
| } else if (slot != thisslot) { | ||
| slot = GETSLOT_CROSSSLOT; /* Mark as cross slot */ | ||
| break; | ||
| } | ||
| } | ||
| getKeysFromCommand(cmd, argv, argc, &result); | ||
|
|
||
| /* Extract slot from the keys result. */ | ||
| int slot = extractSlotFromKeysResult(argv, &result); | ||
| getKeysFreeResult(&result); | ||
|
Comment on lines
428
to
439
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix off-by-one in
🐛 Suggested fix in
|
||
| return slot; | ||
| } | ||
|
|
@@ -3209,10 +3198,9 @@ int extractKeysAndSlot(struct redisCommand *cmd, robj **argv, int argc, | |
| } | ||
| } | ||
|
|
||
| *slot = INVALID_CLUSTER_SLOT; | ||
| if (num_keys >= 0) | ||
| if (num_keys > 0) { | ||
| *slot = extractSlotFromKeysResult(argv, result); | ||
|
|
||
| } | ||
| return num_keys; | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix off-by-one loop to avoid OOB access.
Line 1112 iterates
j <= keys_result->numkeys, which readskeys_result->keys[numkeys]and writesslot_buffer[numkeys]out of bounds. This can corrupt memory or crash.🛠️ Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents