Skip to content
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

(MODULES-6129) negated option with address mask bugfix #756

Merged
merged 1 commit into from
Feb 21, 2018

Conversation

mirekys
Copy link
Contributor

@mirekys mirekys commented Jan 26, 2018

This fixes the issues with rules in the following format (e. g. used by Docker),
where exclamation mark precedes an option followed by outiface:

"-A FORWARD -i br-123456 ! -o br-123456 -j ACCEPT"

Without the fix, it is being parsed like this:

# we do a similar thing for negated address masks (source and destination).
values = values.gsub(/(-\S+) (!)\s?(\S*)/,'\1 "\2 \3"')
#=> "-A FORWARD -i br-123456 \"! -o\" br-123456 -j ACCEPT"

# the actual rule will have the ! mark before the option.
values = values.gsub(/(!)\s*(-\S+)\s*(\S*)/, '\2 "\1 \3"')
#=> "-A FORWARD br-123456 \"-o\" \"! br-123456\" ACCEPT"

Which, in the end, results in:

values = ["ACCEPT", "\"! br-123456\"", "\"-o\"", "br-123456", "FORWARD"]
keys = [:jump, :iniface, :chain]
Error: Failed to apply catalog: Parser error: keys (3) and values (5) count mismatch on line: -A FORWARD -i br-123456 ! -o br-123456 -j ACCEPT

The simple solution is to switch those two gsubs, so it shifts the ! behind option first and only then it quotes the ! together with an option argument (e.g. outiface):

values = values.gsub(/(!)\s*(-\S+)\s*(\S*)/, '\2 "\1 \3"')
#=> "-A FORWARD -i br-123456 ! -o br-123456 -j ACCEPT"

values = values.gsub(/(-\S+) (!)\s?(\S*)/,'\1 "\2 \3"')
#=> "-A FORWARD -i br-123456 -o \"! br-123456\" -j ACCEPT"

A value in this format is then picked up by the parser correctly.

@david22swan david22swan merged commit 129959e into puppetlabs:master Feb 21, 2018
@pmcmaw pmcmaw added the bugfix label Sep 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants