-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Fix comparison of IPv6 addresses in session_get_bydata() #1187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: devel
Are you sure you want to change the base?
Changes from 2 commits
09d16b3
238953b
5aca723
fe3371f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -89,6 +89,37 @@ dumpItemsToString(struct list *self, char *outstr, int len) | |
| return outstr ; | ||
| } | ||
|
|
||
| /* find the last occurrence of ch in str limited by n */ | ||
| static int | ||
| last_index_of(const char *str, char ch, int n) | ||
| { | ||
| int last_colon = -1; | ||
| int i; | ||
|
|
||
| for (i = 0; i < n && str[i] != 0; i++) | ||
| { | ||
| if (str[i] == ch) | ||
| last_colon = i; | ||
| } | ||
|
|
||
| return last_colon; | ||
| } | ||
|
|
||
| /* 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, size_t n) | ||
|
||
| { | ||
| int last_colon_ip1 = last_index_of(ip1, ':', n); | ||
| int last_colon_ip2 = last_index_of(ip2, ':', n); | ||
|
|
||
| if (last_colon_ip1 != last_colon_ip2) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please always use brackets. |
||
| return 0; | ||
|
|
||
| if (last_colon_ip1 == -1) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
| last_colon_ip1 = n; | ||
|
|
||
| return g_strncmp(ip1, ip2, last_colon_ip1) == 0; | ||
| } | ||
|
|
||
| /******************************************************************************/ | ||
| struct session_item * | ||
|
|
@@ -141,7 +172,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 && | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function should be placed
common/because it has nothing sesman-specific.It looks general helper function handling string.