Skip to content

Commit 93f38b6

Browse files
committed
lib/puppet/provider/firewall/iptables.rb - comments cleanup for parsing
Per <https://tickets.puppetlabs.com/browse/MODULES-6876>, there are problems with parsing some iptables rules with space and quotes (specifically ones created by podman). This re-clears the comments field if it made it through earlier parsing.
1 parent c87778e commit 93f38b6

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22

33
All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org).
44

5+
## Unversioned
6+
7+
### iptables.rb
8+
9+
There are cases where spaces and quotes in iptables comments generated by
10+
mainstream sources (e.g. podman) were causing rules to not parse properly.
11+
We didn't fix the whole problem, but we removed those comments for parsing
12+
purposes.1
13+
514
## [v3.0.0](https://github.com/puppetlabs/puppetlabs-firewall/tree/v3.0.0) (2021-03-01)
615

716
[Full Changelog](https://github.com/puppetlabs/puppetlabs-firewall/compare/v2.8.1...v3.0.0)

lib/puppet/provider/firewall/iptables.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,11 @@ def self.rule_to_hash(line, table, counter)
575575
keys << :table
576576
end
577577

578+
# manually remove comments if they made it this far
579+
if values =~ %r{-m comment --comment}
580+
values = values.sub(%r{-m comment --comment "((?:\\"|[^"])*)"}, {})
581+
end
582+
578583
valrev = values.scan(%r{("([^"\\]|\\.)*"|\S+)}).transpose[0].reverse
579584

580585
if keys.length != valrev.length

0 commit comments

Comments
 (0)