Skip to content

Commit f0ced3d

Browse files
committed
(GH-1158) Fix for state/ctstate/ctstatus
Values are being compared incorrectly when multiple negated values are passed. Simplest fix is to fold code into `dport/sport` comparison.
1 parent c05b989 commit f0ced3d

File tree

1 file changed

+5
-23
lines changed

1 file changed

+5
-23
lines changed

lib/puppet/provider/firewall/firewall.rb

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -384,21 +384,6 @@ def insync?(context, _name, property_name, is_hash, should_hash)
384384
when :mac_source, :jump
385385
# Value of mac_source/jump may be downcased or upcased when returned depending on the OS
386386
is_hash[property_name].casecmp(should_hash[property_name]).zero?
387-
when :state, :ctstate, :ctstatus
388-
# Ensure that if both is and should are array values, they are correctly compared in order
389-
is = is_hash[property_name]
390-
should = should_hash[property_name]
391-
return nil unless is.is_a?(Array) && should.is_a?(Array)
392-
393-
if is[0].start_with?('!')
394-
is.append('!')
395-
is[0] = is[0].gsub(%r{^!\s?}, '')
396-
end
397-
if should[0].start_with?('!')
398-
should.append('!')
399-
should[0] = should[0].gsub(%r{^!\s?}, '')
400-
end
401-
is.sort == should.sort
402387
when :icmp
403388
# Ensure that the values are compared to each other as icmp code numbers
404389
is = PuppetX::Firewall::Utility.icmp_name_to_number(is_hash[property_name], is_hash[:protocol])
@@ -428,13 +413,12 @@ def insync?(context, _name, property_name, is_hash, should_hash)
428413
should = "#{should}:00" if %r{^([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$}.match?(should)
429414

430415
is == should
431-
when :dport, :sport
416+
when :dport, :sport, :state, :ctstate, :ctstatus
432417
is = is_hash[property_name]
433418
should = should_hash[property_name]
434419

435-
# Wrap compared values as arrays in order to simplify comparisons
436-
is = [is] unless is.is_a?(Array)
437-
should = [should] unless should.is_a?(Array)
420+
# Unique logic is only needed when both values are arrays
421+
return nil unless is.is_a?(Array) && should.is_a?(Array)
438422

439423
# Ensure values are sorted
440424
# Ensure any negation includes only the first value
@@ -447,13 +431,11 @@ def insync?(context, _name, property_name, is_hash, should_hash)
447431
should_negated = true if %r{^!\s}.match?(should[0].to_s)
448432
should.each_with_index do |_value, _index|
449433
should = should.map { |value| value.to_s.tr('! ', '') }.sort
450-
# Range can be passed as `-` but will always be set/returned as `:`
451-
should = should.map { |value| value.to_s.tr('-', ':') }.sort
434+
# Port range can be passed as `-` but will always be set/returned as `:`
435+
should = should.map { |value| value.to_s.tr('-', ':') }.sort if [:dport, :sport].include?(property_name)
452436
end
453437
should[0] = ['!', should[0]].join(' ') if should_negated
454438

455-
# Range can be passed as `-` but will always be set/returned as `:`
456-
# Ensure values are sorted
457439
is == should
458440
when :string_hex
459441
# Compare the values with any whitespace removed

0 commit comments

Comments
 (0)