From 66d8b6e43447eeebe1ca1c2f79fa4b52173a1b6b Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Thu, 26 Sep 2019 12:07:29 +0100 Subject: [PATCH] [Fix] Do not call implicit strlen to avoid issues --- src/libmime/message.c | 2 +- src/libserver/cfg_rcl.c | 2 +- src/libutil/addr.c | 10 +++++----- src/lua/lua_ip.c | 9 +++++---- src/lua/lua_task.c | 5 +++-- src/lua/lua_tcp.c | 4 ++-- src/lua/lua_udp.c | 2 +- src/rspamadm/control.c | 2 +- src/rspamd.c | 2 +- test/rspamd_upstream_test.c | 4 ++-- 10 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/libmime/message.c b/src/libmime/message.c index ef725e72c..9e9d27d8a 100644 --- a/src/libmime/message.c +++ b/src/libmime/message.c @@ -1287,7 +1287,7 @@ rspamd_message_parse (struct rspamd_task *task) if (recv->real_ip) { if (!rspamd_parse_inet_address (&task->from_addr, recv->real_ip, - 0)) { + strlen (recv->real_ip))) { msg_warn_task ("cannot get IP from received header: '%s'", recv->real_ip); task->from_addr = NULL; diff --git a/src/libserver/cfg_rcl.c b/src/libserver/cfg_rcl.c index 86d674c08..04bd9eefc 100644 --- a/src/libserver/cfg_rcl.c +++ b/src/libserver/cfg_rcl.c @@ -3260,7 +3260,7 @@ rspamd_rcl_parse_struct_addr (rspamd_mempool_t *pool, if (ucl_object_type (obj) == UCL_STRING) { val = ucl_object_tostring (obj); - if (!rspamd_parse_inet_address (target, val, 0)) { + if (!rspamd_parse_inet_address (target, val, strlen (val))) { g_set_error (err, CFG_RCL_ERROR, EINVAL, diff --git a/src/libutil/addr.c b/src/libutil/addr.c index 9e2e76f23..7ab5e11ee 100644 --- a/src/libutil/addr.c +++ b/src/libutil/addr.c @@ -689,13 +689,13 @@ rspamd_parse_inet_address_common (rspamd_inet_addr_t **target, guint iplen; gulong portnum; - g_assert (src != NULL); - g_assert (target != NULL); - if (srclen == 0) { - srclen = strlen (src); + return FALSE; } + g_assert (src != NULL); + g_assert (target != NULL); + rspamd_ip_check_ipv6 (); if (src[0] == '/' || src[0] == '.') { @@ -1387,7 +1387,7 @@ rspamd_parse_host_port_priority (const gchar *str, } } - if (!rspamd_parse_inet_address (&cur_addr, str, 0)) { + if (!rspamd_parse_inet_address (&cur_addr, str, strlen (str))) { msg_err_pool_check ("cannot parse unix socket definition %s: %s", str, strerror (errno)); diff --git a/src/lua/lua_ip.c b/src/lua/lua_ip.c index 942817b5c..8318125ba 100644 --- a/src/lua/lua_ip.c +++ b/src/lua/lua_ip.c @@ -369,13 +369,14 @@ lua_ip_from_string (lua_State *L) LUA_TRACE_POINT; struct rspamd_lua_ip *ip; const gchar *ip_str; + gsize len; - ip_str = luaL_checkstring (L, 1); + ip_str = luaL_checklstring (L, 1, &len); if (ip_str) { ip = lua_ip_new (L, NULL); - if (!rspamd_parse_inet_address (&ip->addr, ip_str, 0)) { - msg_warn ("cannot parse ip: %s", ip_str); + if (!rspamd_parse_inet_address (&ip->addr, ip_str, len)) { + msg_warn ("cannot parse ip: %*s", (gint) len, ip_str); ip->addr = NULL; } } @@ -559,7 +560,7 @@ rspamd_lua_ip_push_fromstring (lua_State *L, const gchar *ip_str) else { ip = g_malloc0 (sizeof (struct rspamd_lua_ip)); - if (rspamd_parse_inet_address (&ip->addr, ip_str, 0)) { + if (rspamd_parse_inet_address (&ip->addr, ip_str, strlen (ip_str))) { pip = lua_newuserdata (L, sizeof (struct rspamd_lua_ip *)); rspamd_lua_setclass (L, "rspamd{ip}", -1); diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c index d2d0c872a..af1a12fae 100644 --- a/src/lua/lua_task.c +++ b/src/lua/lua_task.c @@ -3856,7 +3856,8 @@ lua_task_set_from_ip (lua_State *L) { LUA_TRACE_POINT; struct rspamd_task *task = lua_check_task (L, 1); - const gchar *ip_str = luaL_checkstring (L, 2); + gsize len; + const gchar *ip_str = luaL_checklstring (L, 2, &len); rspamd_inet_addr_t *addr = NULL; if (!task || !ip_str) { @@ -3866,7 +3867,7 @@ lua_task_set_from_ip (lua_State *L) else { if (!rspamd_parse_inet_address (&addr, ip_str, - 0)) { + len)) { msg_warn_task ("cannot get IP from received header: '%s'", ip_str); } diff --git a/src/lua/lua_tcp.c b/src/lua/lua_tcp.c index 10c57cea4..18c022c38 100644 --- a/src/lua/lua_tcp.c +++ b/src/lua/lua_tcp.c @@ -1760,7 +1760,7 @@ lua_tcp_request (lua_State *L) } } - if (rspamd_parse_inet_address (&cbd->addr, host, 0)) { + if (rspamd_parse_inet_address (&cbd->addr, host, strlen (host))) { rspamd_inet_address_set_port (cbd->addr, port); /* Host is numeric IP, no need to resolve */ lua_tcp_register_watcher (cbd); @@ -1942,7 +1942,7 @@ lua_tcp_connect_sync (lua_State *L) } } - if (rspamd_parse_inet_address (&cbd->addr, host, 0)) { + if (rspamd_parse_inet_address (&cbd->addr, host, strlen (host))) { rspamd_inet_address_set_port (cbd->addr, (guint16)port); /* Host is numeric IP, no need to resolve */ if (!lua_tcp_make_connection (cbd)) { diff --git a/src/lua/lua_udp.c b/src/lua/lua_udp.c index 94d27bf63..966ce9788 100644 --- a/src/lua/lua_udp.c +++ b/src/lua/lua_udp.c @@ -373,7 +373,7 @@ lua_udp_sendto (lua_State *L) { if (lua_type (L, -1) == LUA_TSTRING) { host = luaL_checkstring (L, -1); - if (rspamd_parse_inet_address (&addr, host, 0)) { + if (rspamd_parse_inet_address (&addr, host, strlen (host))) { if (port != 0) { rspamd_inet_address_set_port (addr, port); } diff --git a/src/rspamadm/control.c b/src/rspamadm/control.c index cdc504456..2f73d09ca 100644 --- a/src/rspamadm/control.c +++ b/src/rspamadm/control.c @@ -220,7 +220,7 @@ rspamadm_control (gint argc, gchar **argv, const struct rspamadm_command *_cmd) exit (1); } - if (!rspamd_parse_inet_address (&addr, control_path, 0)) { + if (!rspamd_parse_inet_address (&addr, control_path, strlen (control_path))) { rspamd_fprintf (stderr, "bad control path: %s\n", control_path); exit (1); } diff --git a/src/rspamd.c b/src/rspamd.c index 08f91674b..aa8a6235b 100644 --- a/src/rspamd.c +++ b/src/rspamd.c @@ -1323,7 +1323,7 @@ main (gint argc, gchar **argv, gchar **env) if (rspamd_main->cfg->control_socket_path) { if (!rspamd_parse_inet_address (&control_addr, rspamd_main->cfg->control_socket_path, - 0)) { + strlen (rspamd_main->cfg->control_socket_path))) { msg_err_main ("cannot parse inet address %s", rspamd_main->cfg->control_socket_path); } diff --git a/test/rspamd_upstream_test.c b/test/rspamd_upstream_test.c index 7813f9c22..12e478793 100644 --- a/test/rspamd_upstream_test.c +++ b/test/rspamd_upstream_test.c @@ -83,9 +83,9 @@ rspamd_upstream_test_func (void) RSPAMD_UPSTREAM_PARSE_DEFAULT, NULL)); up = rspamd_upstream_get (nls, RSPAMD_UPSTREAM_RANDOM, NULL, 0); - rspamd_parse_inet_address (&paddr, "127.0.0.2", 0); + rspamd_parse_inet_address (&paddr, "127.0.0.2", strlen ("127.0.0.2")); g_assert (rspamd_upstream_add_addr (up, paddr)); - rspamd_parse_inet_address (&paddr, "::1", 0); + rspamd_parse_inet_address (&paddr, "::1", strlen ("::1")); g_assert (rspamd_upstream_add_addr (up, paddr)); /* Rewind to start */ addr = rspamd_upstream_addr_next (up); -- 2.39.5