Skip to content

Fix RM_ScanKey module api not to return int encoded strings#7396

Merged
antirez merged 1 commit intoredis:unstablefrom
MeirShpilraien:fix_dict_scan_module_api
Jun 15, 2020
Merged

Fix RM_ScanKey module api not to return int encoded strings#7396
antirez merged 1 commit intoredis:unstablefrom
MeirShpilraien:fix_dict_scan_module_api

Conversation

@MeirShpilraien
Copy link

The scan key module API provides the scan callback with the current
field name and value (if it exists). Those arguments are RedisModuleString*
which means it supposes to point to robj which is encoded as a string.
Using createStringObjectFromLongLong function might return robj that
points to an integer and so break a module that tries for example to
use RedisModule_StringPtrLen on the given field/value.

The PR introduces a fix that uses the createObject function and sdsfromlonglong function.
Using those function promise that the field and value pass to the to the
scan callback will be Strings.

The PR also changes the Scan test module to use RedisModule_StringPtrLen
to catch the issue. without this, the issue is hidden because
RedisModule_ReplyWithString knows to handle integer encoding of the
given robj (RedisModuleString).

The PR also introduces a new test to verify the issue is solved.

The scan key module API provides the scan callback with the current
field name and value (if it exists). Those arguments are RedisModuleString*
which means it supposes to point to robj which is encoded as a string.
Using createStringObjectFromLongLong function might return robj that
points to an integer and so break a module that tries for example to
use RedisModule_StringPtrLen on the given field/value.

The PR introduces a fix that uses the createObject function and sdsfromlonglong function.
Using those function promise that the field and value pass to the to the
scan callback will be Strings.

The PR also changes the Scan test module to use RedisModule_StringPtrLen
to catch the issue. without this, the issue is hidden because
RedisModule_ReplyWithString knows to handle integer encoding of the
given robj (RedisModuleString).

The PR also introduces a new test to verify the issue is solved.
@antirez antirez merged commit 6ce2ed8 into redis:unstable Jun 15, 2020
@antirez
Copy link
Contributor

antirez commented Jun 15, 2020

Thanks @MeirShpilraien

@MeirShpilraien
Copy link
Author

@antirez sure.
Any chance we can cherry-pick it to Redis 6?

@antirez
Copy link
Contributor

antirez commented Jun 15, 2020 via email

JackieXie168 pushed a commit to JackieXie168/redis that referenced this pull request Jun 18, 2020
…e_api

Fix RM_ScanKey module api not to return int encoded strings
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants