sagpant / simpleai

Other
0 stars 1 forks source link

Potential issue in src/libs/lua/lstrlib.c: Unchecked return from initialization function #2

Open monocle-ai opened 4 years ago

monocle-ai commented 4 years ago

What is a Conditionally Uninitialized Variable? The return value of a function that is potentially used to initialize a local variable is not checked. Therefore, reading the local variable may result in undefined behavior.

1 instance of this defect were found in the following locations:

Instance 1 File : src/libs/lua/lstrlib.c Function: luaL_checklstring https://github.com/sagpant/simpleai/blob/db3acd891f46f67ae70c271bf88a46e6e6b28b0f/src/libs/lua/lstrlib.c#L56 Issue in: l

Code extract:


static int str_len (lua_State *L) {
  size_t l;
  luaL_checklstring(L, 1, &l); <------ HERE
  lua_pushinteger(L, (lua_Integer)l);
  return 1;

How can I fix it? Correct reference usage found in src/libs/lua/lstrlib.c at line 1397. https://github.com/sagpant/simpleai/blob/db3acd891f46f67ae70c271bf88a46e6e6b28b0f/src/libs/lua/lstrlib.c#L1397 Code extract:

      }
      case Kzstr: {  /* zero-terminated string */
        size_t len;
        const char *s = luaL_checklstring(L, arg, &len); <------ HERE
        luaL_argcheck(L, strlen(s) == len, arg, "string contains zeros");
        luaL_addlstring(&b, s, len);
siva-msft commented 4 years ago

Doesn't look like a valid issue... likely fp