Skip to content

Commit cdacb3f

Browse files
peeyushguptaGeert Vanderkelen
authored and
Geert Vanderkelen
committed
BUG19703022: Fix using passwords with integers only in option files
Passwords consisting of only integers were raising error when used with option files. We fix this by not evaluating value for password option in option files. Unit tests are updated. (cherry picked from commit 677b310)
1 parent 3889e86 commit cdacb3f

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

lib/mysql/connector/optionfiles.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,14 @@ def read_option_files(**config):
103103
except KeyError:
104104
continue
105105

106+
not_evaluate = ('password', 'passwd')
106107
for option, value in config_options.items():
107108
if option not in config:
108109
try:
109-
config[option] = eval(value[0]) # pylint: disable=W0123
110+
if option in not_evaluate:
111+
config[option] = value[0]
112+
else:
113+
config[option] = eval(value[0]) # pylint: disable=W0123
110114
except (NameError, SyntaxError):
111115
config[option] = value[0]
112116

tests/data/option_files/my.cnf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
[client]
3+
password=12345
34
port=1000
45
socket=/var/run/mysqld/mysqld.sock
56
ssl-ca=dummyCA

tests/test_optionfiles.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ def test_read(self,):
9999

100100
def test_get_groups(self):
101101
exp = {
102+
'password': '12345',
102103
'port': '1001',
103104
'socket': '/var/run/mysqld/mysqld2.sock',
104105
'ssl-ca': 'dummyCA',
@@ -122,6 +123,7 @@ def test_get_groups(self):
122123
def test_get_groups_as_dict(self):
123124
exp = dict([
124125
('client', {'port': '1000',
126+
'password': '12345',
125127
'socket': '/var/run/mysqld/mysqld.sock',
126128
'ssl-ca': 'dummyCA',
127129
'ssl-cert': 'dummyCert',
@@ -167,6 +169,7 @@ def test_read_option_files(self):
167169

168170
option_file_dir = os.path.join('tests', 'data', 'option_files')
169171
exp = {
172+
'password': '12345',
170173
'port': 1000,
171174
'unix_socket': '/var/run/mysqld/mysqld.sock',
172175
'ssl_ca': 'dummyCA',
@@ -177,6 +180,7 @@ def test_read_option_files(self):
177180
option_file_dir, 'my.cnf'))
178181
self.assertEqual(exp, result)
179182
exp = {
183+
'password': '12345',
180184
'port': 1001,
181185
'unix_socket': '/var/run/mysqld/mysqld2.sock',
182186
'ssl_ca': 'dummyCA',

0 commit comments

Comments
 (0)