Skip to content

Commit 571b0b3

Browse files
fix problem with 0-length string
message: Non-initialized "ptr" is passed to "lua_pushlstring" as const When input length is zero the transformation loop does not run, leaving buffer contents uninitialized. Although lua_pushlstring with length 0 would not read from ptr, some static analyzers flag this as use of uninitialized data. Provide explicit fast-path for n==0 to make intent clear and silence warnings (CERT_C-EXP33-a-1).
1 parent bf05c16 commit 571b0b3

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/lcurl.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,11 @@ static int push_upper(lua_State *L, const char *str){
230230
size_t i, n = strlen(str);
231231
char *ptr = (n < sizeof(buffer))?&buffer[0]:malloc(n + 1);
232232
if (!ptr) return 1;
233+
if (n == 0) {
234+
lua_pushlstring(L, "", 0);
235+
if(ptr != &buffer[0]) free(ptr);
236+
return 0;
237+
}
233238
for(i = 0; i < n; ++i){
234239
if( (str[i] > 96 ) && (str[i] < 123) ) ptr[i] = str[i] - 'a' + 'A';
235240
else ptr[i] = str[i];

0 commit comments

Comments
 (0)