Skip to content

Commit

Permalink
Fix escaped backslashes in grants
Browse files Browse the repository at this point in the history
* Mysql uses the underscore character to represent a single character
  wildcard.
* A grant on table `the_database`.* would match `theAdatabase`.*, so
  underscores must be escaped to avoid this match.
* The output from mysql escapes special characters (\n, \t, \0, and \\),
  but the input does not need to be escaped.
* In order for the provider to compare the tables, the output of
  mysql -NBe <query> must have \\ substituted with \.
  • Loading branch information
skroll committed Nov 5, 2014
1 parent 40dd180 commit 9dbdd89
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/puppet/provider/mysql_grant/mysql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ def self.instances
# Matching: GRANT (SELECT, UPDATE) PRIVILEGES ON (*.*) TO ('root')@('127.0.0.1') (WITH GRANT OPTION)
if match = munged_grant.match(/^GRANT\s(.+)\sON\s(.+)\sTO\s(.*)@(.*?)(\s.*)?$/)
privileges, table, user, host, rest = match.captures
table.gsub!('\\\\', '\\')

# split on ',' if it is not a non-'('-containing string followed by a
# closing parenthesis ')'-char - e.g. only split comma separated elements not in
# parentheses
Expand Down

0 comments on commit 9dbdd89

Please sign in to comment.