Skip to content

Commit

Permalink
Don't pass unsigned short * into a function that expects
Browse files Browse the repository at this point in the history
unsigned int *. This fixes the following error building with
gcc on ubuntu-22:

sipmemcache.c: In function `l_sipmemcache_server_add`:
../../ut.h:685:13: error: array subscript `unsigned int[0]` is partly outside array bounds of `in_port_t[1]` {aka `short unsigned int[1]`} [-Werror=array-bounds]
  685 |         *_r = 0;
      |         ~~~~^~~
sipmemcache.c:72:13: note: while referencing `iport`
   72 |   in_port_t iport = 0;
      |             ^~~~~
  • Loading branch information
sobomax committed Mar 23, 2023
1 parent 6389c36 commit 2422396
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions modules/lua/sipmemcache.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ static int l_sipmemcache_server_add(lua_State *L)
struct sipmemcache *o;
const char *host;
const char *port;
in_port_t iport;
in_port_t iport = 0;
unsigned int _port = 0;
str s;

o = luaL_checkudata(L, 1, "siplua.memcache");
Expand All @@ -83,10 +84,12 @@ static int l_sipmemcache_server_add(lua_State *L)
{
s.len = strlen(port);
s.s = (char *)port;
if (str2int(&s, (unsigned int *)&iport) < 0)
if (str2int(&s, (unsigned int *)&_port) < 0 || _port > USHRT_MAX) {
lua_pushboolean(L, 0);
else
} else {
lua_pushboolean(L, 1);
iport = _port;
}
servers = memcached_server_list_append(servers, host, iport, &rc);
if (rc != MEMCACHED_SUCCESS) {
LM_ERR("cannot add server: %s\n", memcached_strerror(&o->memc, rc));
Expand Down

0 comments on commit 2422396

Please sign in to comment.