diff --git a/common/os_calls.c b/common/os_calls.c index e7fc144cd0..e2946e7575 100644 --- a/common/os_calls.c +++ b/common/os_calls.c @@ -2822,6 +2822,22 @@ g_pos(const char *str, const char *to_find) return (pp - str); } +/*****************************************************************************/ +int +g_last_ch_pos(const char *str, char ch_to_find, const int n) +{ + int last_pos = -1; + int i; + + for (i = 0; i < n && str[i] != 0; i++) + { + if (str[i] == ch_to_find) + last_pos = i; + } + + return last_pos; +} + /*****************************************************************************/ int g_mbstowcs(twchar *dest, const char *src, int n) diff --git a/common/os_calls.h b/common/os_calls.h index e42e95bde0..942ed28ff9 100644 --- a/common/os_calls.h +++ b/common/os_calls.h @@ -135,6 +135,7 @@ int g_htoi(char* str); int g_bytes_to_hexstr(const void *bytes, int num_bytes, char *out_str, int bytes_out_str); int g_pos(const char* str, const char* to_find); +int g_last_ch_pos(const char *str, char ch_to_find, int n); int g_mbstowcs(twchar* dest, const char* src, int n); int g_wcstombs(char* dest, const twchar* src, int n); int g_strtrim(char* str, int trim_flags); diff --git a/sesman/session.c b/sesman/session.c index 0d9fdc7095..c05dac8143 100644 --- a/sesman/session.c +++ b/sesman/session.c @@ -89,6 +89,25 @@ dumpItemsToString(struct list *self, char *outstr, int len) return outstr ; } +/* compare two strings containing ip-addresses and ports but ignore the latter */ +static int +is_equal_ip_ignoring_port(const char *ip1, const char *ip2, const size_t n) +{ + int last_colon_ip1 = g_last_ch_pos(ip1, ':', n); + int last_colon_ip2 = g_last_ch_pos(ip2, ':', n); + + if (last_colon_ip1 != last_colon_ip2) + { + return 0; + } + + if (last_colon_ip1 == -1) + { + last_colon_ip1 = n; + } + + return g_strncmp(ip1, ip2, last_colon_ip1) == 0; +} /******************************************************************************/ struct session_item * @@ -141,7 +160,7 @@ session_get_bydata(const char *name, int width, int height, int bpp, int type, (!(policy & SESMAN_CFG_SESS_POLICY_D) || (tmp->item->width == width && tmp->item->height == height)) && (!(policy & SESMAN_CFG_SESS_POLICY_I) || - (g_strncmp_d(client_ip, tmp->item->client_ip, ':', 255) == 0)) && + is_equal_ip_ignoring_port(client_ip, tmp->item->client_ip, 255)) && (!(policy & SESMAN_CFG_SESS_POLICY_C) || (g_strncmp(client_ip, tmp->item->client_ip, 255) == 0)) && tmp->item->bpp == bpp &&