Merge lp:~gl-az/percona-server/BT-23597-bug1166638-5.6 into lp:percona-server/5.6

Proposed by George Ormond Lorch III
Status: Merged
Approved by: Laurynas Biveinis
Approved revision: no longer in the source branch.
Merged at revision: 439
Proposed branch: lp:~gl-az/percona-server/BT-23597-bug1166638-5.6
Merge into: lp:percona-server/5.6
Diff against target: 133 lines (+46/-15)
1 file modified
Percona-Server/sql/sql_acl.cc (+46/-15)
To merge this branch: bzr merge lp:~gl-az/percona-server/BT-23597-bug1166638-5.6
Reviewer Review Type Date Requested Status
Laurynas Biveinis (community) Approve
Review via email: mp+187901@code.launchpad.net

Description of the change

Merged from 5.5:
Fix for https://bugs.launchpad.net/percona-server/+bug/1166638 - Utility user setup leaks memory | Valgrind: still reachable: malloc in acl_init_utility_user & init_dynamic_array2

Originally this was just written off as a known, one time leak, which is is, but the failure causes scripted testing to fail and is really just sloppy.

To fix, created new status flags that indicate whather or not acl_utility_user and acl_utility_user_schema_access have been initialized. Create new function to clean up utility user resources and call it from acl_free and from acl_init_utility_user to free up if being reinitialized or if there is an error during the initialization. For 5.6 had to move some things around due to the struct++'ing that upstream devs did (turning structs into classes without properly building out rational/smart class interfaces for data access and management).

http://jenkins.percona.com/view/PS%205.6/job/percona-server-5.6-param/319/

To post a comment you must log in.
Revision history for this message
George Ormond Lorch III (gl-az) wrote :
Revision history for this message
Laurynas Biveinis (laurynas-biveinis) wrote :

- Same comment as in 5.5 re. acl_free_utility_user() header comment.
- Any reason 5.6 acl_free_utility_user() does not bzero acl_utility_user like 5.5 does?

review: Needs Information
Revision history for this message
George Ormond Lorch III (gl-az) wrote :

On 9/29/2013 2:04 AM, Laurynas Biveinis wrote:
> Review: Needs Information
>
> - Same comment as in 5.5 re. acl_free_utility_user() header comment.
> - Any reason 5.6 acl_free_utility_user() does not bzero acl_utility_user like 5.5 does?
>
in 5.6 ACL_USER is a class with private members, 5.5 it is just a
struct...the 5.6 struct++ization of the codebase isn't very friendly to
bzeroing of things :)

--
George O. Lorch III
Software Engineer, Percona
+1-888-401-3401 x542 US/Arizona (GMT -7)
skype: george.ormond.lorch.iii

Revision history for this message
Laurynas Biveinis (laurynas-biveinis) wrote :

I think that ACL_USER satisfies C++ POD requirements and is thus safe to memset/memcpy, but still OK to leave this out if you prefer.

Revision history for this message
George Ormond Lorch III (gl-az) wrote :

Fixed acl_free_utility_user comment and went ahead and added back on memset (in place of 5.5 bzero).

Revision history for this message
Laurynas Biveinis (laurynas-biveinis) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Percona-Server/sql/sql_acl.cc'
2--- Percona-Server/sql/sql_acl.cc 2013-08-27 20:55:20 +0000
3+++ Percona-Server/sql/sql_acl.cc 2013-09-30 17:15:58 +0000
4@@ -891,8 +891,11 @@
5 };
6
7 static ACL_USER acl_utility_user;
8+LEX_STRING acl_utility_user_name, acl_utility_user_host_name;
9 static DYNAMIC_ARRAY acl_utility_user_schema_access;
10+static bool acl_utility_user_initialized= false;
11 static my_bool acl_init_utility_user(my_bool check_no_resolve);
12+static void acl_free_utility_user();
13
14 /**
15 Convert scrambled password to binary form, according to scramble type,
16@@ -1462,6 +1465,7 @@
17
18 void acl_free(bool end)
19 {
20+ acl_free_utility_user();
21 free_root(&global_acl_memory,MYF(0));
22 delete_dynamic(&acl_users);
23 delete_dynamic(&acl_dbs);
24@@ -1652,7 +1656,6 @@
25 my_bool
26 acl_init_utility_user(my_bool check_no_resolve)
27 {
28- LEX_STRING acl_user_name, acl_host_name;
29 char password[CRYPT_MAX_PASSWORD_SIZE + 1];
30 uint i, passlen;
31 my_bool ret= TRUE;
32@@ -1660,15 +1663,23 @@
33 if (!utility_user)
34 goto end;
35
36+ acl_free_utility_user();
37+
38+ /* Allocate all initial resources necessary */
39+ acl_utility_user_name.str= (char *) my_malloc(USERNAME_LENGTH+1, MY_ZEROFILL);
40+ acl_utility_user_host_name.str= (char *) my_malloc(HOSTNAME_LENGTH+1, MY_ZEROFILL);
41+ (void) my_init_dynamic_array(&acl_utility_user_schema_access, sizeof(char *),
42+ 5, 10);
43+ acl_utility_user_initialized= true;
44+
45 /* parse out the option to its component user and host name parts */
46- acl_user_name.str= (char *) my_malloc(USERNAME_LENGTH+1, MY_ZEROFILL);
47- acl_host_name.str= (char *) my_malloc(HOSTNAME_LENGTH+1, MY_ZEROFILL);
48 parse_user(utility_user, strlen(utility_user),
49- acl_user_name.str, &acl_user_name.length,
50- acl_host_name.str, &acl_host_name.length);
51+ acl_utility_user_name.str, &acl_utility_user_name.length,
52+ acl_utility_user_host_name.str,
53+ &acl_utility_user_host_name.length);
54
55 /* Check to see if the username is anonymous */
56- if (!acl_user_name.str || acl_user_name.str[0] == '\0')
57+ if (!acl_utility_user_name.str || acl_utility_user_name.str[0] == '\0')
58 {
59 sql_print_error("'utility user' specified as '%s' is anonymous"
60 " and not allowed.",
61@@ -1688,9 +1699,9 @@
62 }
63
64 /* set up some of the static utility user struct fields */
65- acl_utility_user.user= acl_user_name.str;
66+ acl_utility_user.user= acl_utility_user_name.str;
67
68- acl_utility_user.host.update_hostname(acl_host_name.str);
69+ acl_utility_user.host.update_hostname(acl_utility_user_host_name.str);
70
71 acl_utility_user.sort= get_sort(2, acl_utility_user.host.get_host(),
72 acl_utility_user.user);
73@@ -1700,7 +1711,7 @@
74 {
75 ACL_USER *user= dynamic_element(&acl_users, i, ACL_USER*);
76 if (user->user
77- && strcmp(acl_user_name.str, user->user) == 0)
78+ && strcmp(acl_utility_user_name.str, user->user) == 0)
79 {
80 if (user->sort == acl_utility_user.sort)
81 {
82@@ -1774,9 +1785,6 @@
83 (void) push_dynamic(&acl_users,(uchar*) &acl_utility_user);
84
85 /* initialize the schema access list if specified */
86- (void) my_init_dynamic_array(&acl_utility_user_schema_access, sizeof(char *),
87- 5, 10);
88-
89 if (utility_user_schema_access)
90 {
91 char *cur_pos= utility_user_schema_access;
92@@ -1810,15 +1818,38 @@
93 goto end;
94
95 cleanup:
96- my_free(acl_user_name.str);
97- my_free(acl_host_name.str);
98- memset(&acl_utility_user, 0, sizeof(acl_utility_user));
99+ acl_free_utility_user();
100
101 end:
102 return ret;
103 }
104
105 /*
106+ Free up any resources allocated during acl_init_utility_user.
107+*/
108+static
109+void
110+acl_free_utility_user()
111+{
112+ if (acl_utility_user_initialized)
113+ {
114+ uint i;
115+ for (i=0 ; i < acl_utility_user_schema_access.elements ; i++)
116+ {
117+ char** dbname= dynamic_element(&acl_utility_user_schema_access, i, char**);
118+ if (*dbname)
119+ my_free(*dbname);
120+ }
121+ delete_dynamic(&acl_utility_user_schema_access);
122+
123+ my_free(acl_utility_user_name.str);
124+ my_free(acl_utility_user_host_name.str);
125+ memset(&acl_utility_user, 0, sizeof(acl_utility_user));
126+ acl_utility_user_initialized= false;
127+ }
128+}
129+
130+/*
131 Determines if the user specified by user, host, ip matches the utility user
132 */
133 my_bool

Subscribers

People subscribed via source and target branches