Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

@artikell
Copy link
Contributor

Compilation warning in eval.c:244 when extracting shebang flags -
attempting to allocate 18446744073709551615 bytes (SIZE_MAX) due to
unsigned integer underflow.

Signed-off-by: lizhiqiang.sf <lizhiqiang.sf@bytedance.com>
@artikell
Copy link
Contributor Author

my complice environment is:gcc version 12.2.0 (Debian 12.2.0-14) and warning content:

eval.c: In function ‘evalExtractShebangFlags’:
eval.c:244:27: warning: argument 1 value ‘18446744073709551615’ exceeds maximum object size 9223372036854775807 [-Walloc-size-larger-than=]
  244 |             *out_engine = zcalloc(engine_name_len + 1);
      |                           ^
zmalloc.c:256:7: note: in a call to allocation function ‘valkey_calloc’ declared here
  256 | void *zcalloc(size_t size) {
      |       ^
cd modules/lua && make OPTIMIZATION="-O3 -flto=auto -ffat-lto-objects -fno-omit-frame-pointer"

Perhaps you could take a look. cc @rjd15372

@codecov
Copy link

codecov bot commented Dec 22, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 73.88%. Comparing base (992b886) to head (531fb89).

Additional details and impacted files
@@             Coverage Diff              @@
##           unstable    #2963      +/-   ##
============================================
+ Coverage     73.73%   73.88%   +0.14%     
============================================
  Files           125      125              
  Lines         68911    68911              
============================================
+ Hits          50813    50913     +100     
+ Misses        18098    17998     -100     
Files with missing lines Coverage Δ
src/eval.c 87.46% <100.00%> (ø)

... and 20 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dvkashapov
Copy link
Member

Same thing

gcc version 13.3.0 (Ubuntu 13.3.0-6ubuntu2~24.04) 

eval.c: In function ‘evalExtractShebangFlags’:
eval.c:244:27: warning: argument 1 value ‘18446744073709551615’ exceeds maximum object size 9223372036854775807 [-Walloc-size-larger-than=]
  244 |             *out_engine = zcalloc(engine_name_len + 1);
      |                           ^
zmalloc.c:256:7: note: in a call to allocation function ‘valkey_calloc’ declared here
  256 | void *zcalloc(size_t size) {
      |       ^
cd modules/lua && make OPTIMIZATION="-O3 -flto=auto -ffat-lto-objects -fno-omit-frame-pointer"

sds *parts = sdssplitargs(shebang, &numparts);
sdsfree(shebang);
if (!parts || numparts == 0) {
if (!parts || numparts == 0 || sdslen(parts[0]) < 2) {
Copy link
Member

@ranshid ranshid Dec 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix LGTM.

  1. Personally I find it more readable by trimming the shebang prefix first and then treat each argument separately eg:
--- a/src/eval.c
+++ b/src/eval.c
@@ -230,9 +230,8 @@ int evalExtractShebangFlags(sds body,
             return C_ERR;
         }
         shebang_len = shebang_end - body;
-        sds shebang = sdsnewlen(body, shebang_len);
+        sds shebang = sdsnewlen(body + 2, shebang_len - 2);
         sds *parts = sdssplitargs(shebang, &numparts);
-        sdsfree(shebang);
         if (!parts || numparts == 0) {
             if (err) *err = sdsnew("Invalid engine in script shebang");
             sdsfreesplitres(parts, numparts);
@@ -240,9 +239,9 @@ int evalExtractShebangFlags(sds body,
         }
 
         if (out_engine) {
-            size_t engine_name_len = sdslen(parts[0]) - 2;
+            size_t engine_name_len = sdslen(parts[0]);
             *out_engine = zcalloc(engine_name_len + 1);
-            valkey_strlcpy(*out_engine, parts[0] + 2, engine_name_len + 1);
+            valkey_strlcpy(*out_engine, parts[0], engine_name_len + 1);
         }
 
         script_flags &= ~SCRIPT_FLAG_EVAL_COMPAT_MODE;
  1. I would like if we had a len version of sdssplitargs which could help us avoid the unnecessary:
sds shebang = sdsnewlen(body, shebang_len);

as it is only created for the sdssplitargs does not except input string length and is tracking the null terminator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

4 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.