Skip to content

Commit ddd0708

Browse files
ekohlbastelfreak
authored andcommitted
Fix Solaris processors regex
This fixes a CodeQL security scanner hit: > Suspicious character range that overlaps with a-z in the same character class, and is equivalent to [A-Z[]^_`a-z]. It was subtly relying on this. This modifies to code to extract the value directly by scanning the output instead of parsing the output again. Fixes: 7019e89 ("(FACT-2552) Add Solaris processors facts (#451)")
1 parent 876e89c commit ddd0708

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

lib/facter/resolvers/solaris/processors.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ def collect_kstat_info(fact_name)
2626
def parse_output(output)
2727
@fact_list[:logical_count] = output.scan(/module/).size
2828
@fact_list[:physical_count] = output.scan(/chip_id .*/).uniq.size
29-
@fact_list[:speed] = output.scan(/current_clock_Hz .*/).first.gsub(/[a-zA-z\s]+/, '').to_i
29+
# .scan(//current_clock_Hz\s+(\d+)/) returns [['123']] (or [['123'], ['456']] if there are more matches)
30+
@fact_list[:speed] = output.scan(/current_clock_Hz\s+(\d+)/).first&.first&.to_i
3031
@fact_list[:models] = output.scan(/brand .*/).map { |elem| elem.gsub(/brand(\s+)/, '') }
3132
calculate_threads_cores(output)
3233
end

0 commit comments

Comments
 (0)