Skip to content

Optimize kvobjGetExpire by avoiding unnecessary pointer arithmetic and direct typed access #14241

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

Open
wants to merge 1 commit into
base: unstable
Choose a base branch
from

Conversation

chx9
Copy link
Contributor

@chx9 chx9 commented Jul 31, 2025

Optimized performance by avoiding unnecessary pointer arithmetic when expirable is false and using direct typed access.

Copy link

snyk-io bot commented Jul 31, 2025

🎉 Snyk checks have passed. No issues have been found so far.

security/snyk check is complete. No issues have been found. (View Details)

license/snyk check is complete. No issues have been found. (View Details)

@chx9 chx9 changed the title optimize kvobjGetExpire Optimize kvobjGetExpire Jul 31, 2025
@chx9 chx9 changed the title Optimize kvobjGetExpire Optimize kvobjGetExpire by avoiding unnecessary pointer arithmetic when expirable is false and using direct typed access. Jul 31, 2025
@chx9 chx9 changed the title Optimize kvobjGetExpire by avoiding unnecessary pointer arithmetic when expirable is false and using direct typed access. Optimize kvobjGetExpire by avoiding unnecessary pointer arithmetic and direct typed access Jul 31, 2025
@kaplanben
Copy link

Logo
Checkmarx One – Scan Summary & Details57f81daf-236b-41cd-a4ac-1bce08bcb805

New Issues (8)

Checkmarx found the following issues in this Pull Request

Severity Issue Source File / Package Checkmarx Insight
CRITICAL Buffer_Overflow_Wrong_Buffer_Size /src/sha1.c: 65
detailsThe buffer buffer created in /src/sha1.c at line 65 is written to a buffer in /src/sha1.c at line 65 by block, but an error in calculating the al...
ID: N9gGLsUP8UQvFZEl1N39fgD7jYQ%3D
Attack Vector
CRITICAL Buffer_Overflow_Wrong_Buffer_Size /src/redis-cli.c: 3677
detailsThe buffer buf created in /src/redis-cli.c at line 3677 is written to a buffer in /deps/hiredis/sds.c at line 234 by newsh, but an error in calc...
ID: %2BpSSxZAM7xfUiads1egmyYebO5I%3D
Attack Vector
CRITICAL Buffer_Overflow_Wrong_Buffer_Size /deps/linenoise/linenoise.c: 1200
detailsThe buffer buf created in /deps/linenoise/linenoise.c at line 1200 is written to a buffer in /deps/hiredis/sds.c at line 97 by sh, but an error i...
ID: oykVSjUcVC%2FEMplDwW4P3YG7%2FzE%3D
Attack Vector
CRITICAL Buffer_Overflow_Wrong_Buffer_Size /src/redis-cli.c: 3677
detailsThe buffer buf created in /src/redis-cli.c at line 3677 is written to a buffer in /deps/hiredis/sds.c at line 234 by hdrlen, but an error in cal...
ID: zN%2FI3F1XTVrKpHuopU6EZZmWXt4%3D
Attack Vector
CRITICAL Buffer_Overflow_Wrong_Buffer_Size /src/redis-cli.c: 10594
detailsThe buffer argv created in /src/redis-cli.c at line 10594 is written to a buffer in /deps/hiredis/sds.c at line 97 by sh, but an error in calcul...
ID: eStOv%2FTaWfWWBCJCCgzT7mgYJU0%3D
Attack Vector
CRITICAL Buffer_Overflow_Wrong_Buffer_Size /deps/linenoise/linenoise.c: 1166
detailsThe buffer fgetc created in /deps/linenoise/linenoise.c at line 1166 is written to a buffer in /deps/hiredis/sds.c at line 97 by sh, but an error...
ID: v3h9G7I8PLSutWNyC8k4gGzAdDA%3D
Attack Vector
MEDIUM Divide_By_Zero /modules/vector-sets/fastjson_test.c: 121
detailsThe application performs an illegal operation in generate_random_string, in /modules/vector-sets/fastjson_test.c. In line 121, the program at...
ID: qiowoZ%2FDUFf8wA3ZCvKY8M0GHks%3D
Attack Vector
MEDIUM Divide_By_Zero /src/redis-cli.c: 6040
detailsThe application performs an illegal operation in clusterManagerNodeMasterRandom, in /src/redis-cli.c. In line 6053, the program attempts to divi...
ID: Wdmj3BiFZXbdNClmOY%2Fr1waYywk%3D
Attack Vector
Fixed Issues (5)

Great job! The following issues were fixed in this Pull Request

Severity Issue Source File / Package
CRITICAL Buffer_Overflow_Wrong_Buffer_Size /src/redis-cli.c: 3677
CRITICAL Buffer_Overflow_Wrong_Buffer_Size /src/redis-cli.c: 3677
CRITICAL Buffer_Overflow_Wrong_Buffer_Size /src/redis-cli.c: 3677
CRITICAL Buffer_Overflow_Wrong_Buffer_Size /src/redis-cli.c: 3677
MEDIUM Divide_By_Zero /deps/jemalloc/src/nstime.c: 149

@sundb
Copy link
Collaborator

sundb commented Jul 31, 2025

247     long long kvobjGetExpire(const kvobj *kv) {
   0x00000000000e35d0 <+0>:     endbr64

248         unsigned char *data = (void *)(kv + 1);

249         if (kv->expirable) {
   0x00000000000e35d4 <+4>:     testb  $0x2,0x4(%rdi)
   0x00000000000e35d8 <+8>:     je     0xe35e0 <kvobjGetExpire+16>

250             return *(long long *)data;
   0x00000000000e35da <+10>:    mov    0x10(%rdi),%rax
   0x00000000000e35de <+14>:    ret
   0x00000000000e35df <+15>:    nop

251         } else {
252             return -1;
   0x00000000000e35e0 <+16>:    mov    $0xffffffffffffffff,%rax

253         }
254     }
   0x00000000000e35e7 <+23>:    ret
   0x00000000000e35e8:  nopl   0x0(%rax,%rax,1)

seems that 0x00000000000e35da <+10>: mov 0x10(%rdi),%rax was postponed due to compiler optimization.

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.

3 participants