Skip to content

Commit

Permalink
Upgrade supported Ruby version to 3.1 (#259)
Browse files Browse the repository at this point in the history
* Upgrade supported Ruby version to 3.1

* Run rubocop -A

* Suppress warning of deprecated Process::Status#>>
  • Loading branch information
david942j authored Aug 5, 2024
1 parent cefb306 commit 6b4777b
Show file tree
Hide file tree
Showing 14 changed files with 52 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
strategy:
matrix:
os: [ubuntu]
ruby-version: ['3.0', '3.1', '3.2', head]
ruby-version: ['3.1', '3.2', '3.3']

steps:
- uses: actions/checkout@v2
Expand Down
43 changes: 25 additions & 18 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,54 +9,61 @@ GEM
specs:
ast (2.4.2)
diff-lcs (1.5.1)
docile (1.4.0)
json (2.6.3)
docile (1.4.1)
json (2.7.2)
language_server-protocol (3.17.0.3)
os (1.1.4)
parallel (1.22.1)
parser (3.2.2.0)
parallel (1.25.1)
parser (3.3.4.0)
ast (~> 2.4.1)
racc
racc (1.8.1)
rainbow (3.1.1)
rake (13.1.0)
rake (13.2.1)
rake-compiler (1.2.7)
rake
regexp_parser (2.8.0)
rexml (3.2.5)
regexp_parser (2.9.2)
rexml (3.3.4)
strscan
rspec (3.13.0)
rspec-core (~> 3.13.0)
rspec-expectations (~> 3.13.0)
rspec-mocks (~> 3.13.0)
rspec-core (3.13.0)
rspec-support (~> 3.13.0)
rspec-expectations (3.13.0)
rspec-expectations (3.13.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-mocks (3.13.0)
rspec-mocks (3.13.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-support (3.13.0)
rubocop (1.50.2)
rspec-support (3.13.1)
rubocop (1.65.1)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.2.0.0)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
regexp_parser (>= 2.4, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.28.0, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.28.0)
parser (>= 3.2.1.0)
rubocop-ast (1.32.0)
parser (>= 3.3.1.0)
ruby-progressbar (1.13.0)
simplecov (0.22.0)
docile (~> 1.1)
simplecov-html (~> 0.11)
simplecov_json_formatter (~> 0.1)
simplecov-html (0.12.3)
simplecov_json_formatter (0.1.4)
unicode-display_width (2.4.2)
strscan (3.1.0)
unicode-display_width (2.5.0)
yard (0.9.36)

PLATFORMS
ruby
x86_64-linux

DEPENDENCIES
Expand All @@ -69,4 +76,4 @@ DEPENDENCIES
yard (~> 0.9)

BUNDLED WITH
2.3.23
2.5.3
8 changes: 4 additions & 4 deletions lib/seccomp-tools/asm/compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Compiler
# @param [Symbol] arch
# Architecture.
def initialize(source, filename, arch)
@scanner = Scanner.new(source, arch, filename: filename)
@scanner = Scanner.new(source, arch, filename:)
@arch = arch
@symbols = {}
end
Expand Down Expand Up @@ -115,7 +115,7 @@ def emit(*args, k: 0, jt: 0, jf: 0)
code |= Const::BPF::OP.fetch(a, 0)
code |= Const::BPF::MISCOP.fetch(a, 0)
end
BPF.new({ code: code, k: k, jt: jt, jf: jf }, @arch, @line)
BPF.new({ code:, k:, jt:, jf: }, @arch, @line)
end

# A = -A
Expand Down Expand Up @@ -144,7 +144,7 @@ def emit_ld(dst, src)

def emit_alu(op, val)
src, k = val.x? ? [:x, 0] : [:k, val.to_i]
emit(:alu, convert_alu_op(op), src, k: k)
emit(:alu, convert_alu_op(op), src, k:)
end

def convert_alu_op(op)
Expand Down Expand Up @@ -187,7 +187,7 @@ def emit_cmp(cmp, jt_sym, jf_sym)
val = cmp[1]
src = val.x? ? :x : :k
k = val.x? ? 0 : val.to_i
emit(:jmp, jop, src, jt: jt, jf: jf, k: k)
emit(:jmp, jop, src, jt:, jf:, k:)
end

# == != >= <= > < &
Expand Down
6 changes: 4 additions & 2 deletions lib/seccomp-tools/asm/sasm.tab.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions lib/seccomp-tools/asm/scanner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,25 @@ class Scanner
# Keywords with special meanings in our assembly. Keywords are all case-insensitive.
KEYWORDS = %w[a x if else return mem args args_h data len sys_number arch instruction_pointer].freeze
# Regexp for matching keywords.
KEYWORD_MATCHER = /\A\b(#{KEYWORDS.join('|')})\b/i.freeze
KEYWORD_MATCHER = /\A\b(#{KEYWORDS.join('|')})\b/i
# Action strings can be used in a return statement. Actions must be in upper case.
# See {SeccompTools::Const::BPF::ACTION}.
ACTIONS = Const::BPF::ACTION.keys.map(&:to_s)
# Regexp for matching actions.
ACTION_MATCHER = /\A\b(#{ACTIONS.join('|')})\b/.freeze
ACTION_MATCHER = /\A\b(#{ACTIONS.join('|')})\b/
# Special constants for checking the current architecture. See {SeccompTools::Const::Audit::ARCH}. These constants
# are case-insensitive.
AUDIT_ARCHES = Const::Audit::ARCH.keys
# Regexp for matching arch values.
AUDIT_ARCH_MATCHER = /\A\b(#{AUDIT_ARCHES.join('|')})\b/i.freeze
AUDIT_ARCH_MATCHER = /\A\b(#{AUDIT_ARCHES.join('|')})\b/i
# Comparisons.
COMPARE = %w[== != >= <= > <].freeze
# Regexp for matching comparisons.
COMPARE_MATCHER = /\A(#{COMPARE.join('|')})/.freeze
COMPARE_MATCHER = /\A(#{COMPARE.join('|')})/
# All valid arithmetic operators.
ALU_OP = %w[+ - * / | ^ << >>].freeze
# Regexp for matching ALU operators.
ALU_OP_MATCHER = /\A(#{ALU_OP.map { |o| ::Regexp.escape(o) }.join('|')})/.freeze
ALU_OP_MATCHER = /\A(#{ALU_OP.map { |o| ::Regexp.escape(o) }.join('|')})/
# Supported architectures
ARCHES = SeccompTools::Syscall::ABI.keys.map(&:to_s)

Expand Down
2 changes: 1 addition & 1 deletion lib/seccomp-tools/cli/asm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Asm < Base
# Summary of this command.
SUMMARY = 'Seccomp bpf assembler.'
# Usage of this command.
USAGE = "asm - #{SUMMARY}\n\nUsage: seccomp-tools asm IN_FILE [options]"
USAGE = "asm - #{SUMMARY}\n\nUsage: seccomp-tools asm IN_FILE [options]".freeze

def initialize(*)
super
Expand Down
2 changes: 1 addition & 1 deletion lib/seccomp-tools/cli/disasm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Disasm < Base
# Summary of this command.
SUMMARY = 'Disassemble seccomp bpf.'
# Usage of this command.
USAGE = "disasm - #{SUMMARY}\n\nUsage: seccomp-tools disasm BPF_FILE [options]"
USAGE = "disasm - #{SUMMARY}\n\nUsage: seccomp-tools disasm BPF_FILE [options]".freeze

def initialize(*)
super
Expand Down
4 changes: 2 additions & 2 deletions lib/seccomp-tools/cli/dump.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Dump < Base
SUMMARY = 'Automatically dump seccomp bpf from execution file(s).'
# Usage of this command.
USAGE = "dump - #{SUMMARY}\nNOTE : This function is only available on Linux." \
"\n\nUsage: seccomp-tools dump [exec] [options]"
"\n\nUsage: seccomp-tools dump [exec] [options]".freeze

def initialize(*)
super
Expand Down Expand Up @@ -72,7 +72,7 @@ def handle
case option[:format]
when :inspect then output { "\"#{bpf.bytes.map { |b| format('\\x%02X', b) }.join}\"\n" }
when :raw then output { bpf }
when :disasm then output { SeccompTools::Disasm.disasm(bpf, arch: arch) }
when :disasm then output { SeccompTools::Disasm.disasm(bpf, arch:) }
end
end
if option[:pid].nil?
Expand Down
4 changes: 2 additions & 2 deletions lib/seccomp-tools/cli/emu.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Emu < Base
# Summary of this command.
SUMMARY = 'Emulate seccomp rules.'
# Usage of this command.
USAGE = "emu - #{SUMMARY}\n\nUsage: seccomp-tools emu [options] BPF_FILE [sys_nr [arg0 [arg1 ... arg5]]]"
USAGE = "emu - #{SUMMARY}\n\nUsage: seccomp-tools emu [options] BPF_FILE [sys_nr [arg0 [arg1 ... arg5]]]".freeze

def initialize(*)
super
Expand Down Expand Up @@ -50,7 +50,7 @@ def handle
sys = evaluate_sys_nr(sys) if sys
args.map! { |v| Integer(v) }
trace = Set.new
res = SeccompTools::Emulator.new(insts, sys_nr: sys, args: args, arch: option[:arch]).run do |ctx|
res = SeccompTools::Emulator.new(insts, sys_nr: sys, args:, arch: option[:arch]).run do |ctx|
trace << ctx[:pc]
end

Expand Down
2 changes: 1 addition & 1 deletion lib/seccomp-tools/disasm/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def load(reg, rel: nil, val: nil)
values[reg] = if rel == :mem
values[val]
else
Value.new(rel: rel, val: val)
Value.new(rel:, val:)
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/seccomp-tools/disasm/disasm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def disasm(raw, arch: nil, display_bpf: true, arg_infer: true)
end
end
code.contexts = ctxs
code.disasm(code: display_bpf, arg_infer: arg_infer)
code.disasm(code: display_bpf, arg_infer:)
end.join("\n")
if display_bpf
<<-EOS
Expand Down
2 changes: 1 addition & 1 deletion lib/seccomp-tools/dumper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def wait_syscall
child, status = Process.wait2
cont = true
# TODO: Test if clone / vfork works
if [Ptrace::EVENT_CLONE, Ptrace::EVENT_FORK, Ptrace::EVENT_VFORK].include?(status >> 16)
if [Ptrace::EVENT_CLONE, Ptrace::EVENT_FORK, Ptrace::EVENT_VFORK].include?(status.to_i >> 16)
# New child launched!
# newpid = SeccompTools::Ptrace.geteventmsg(child)
elsif status.stopped? && status.stopsig & 0x80 != 0
Expand Down
2 changes: 1 addition & 1 deletion seccomp-tools.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Visit https://github.com/david942j/seccomp-tools for more details.
'source_code_uri' => 'https://github.com/david942j/seccomp-tools'
}

s.required_ruby_version = '>= 2.6'
s.required_ruby_version = '>= 3.1'

s.add_development_dependency 'rake', '~> 13.0'
s.add_development_dependency 'rake-compiler', '~> 1.0'
Expand Down
6 changes: 3 additions & 3 deletions spec/emulator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
code |= SeccompTools::Const::BPF::SRC[:a]
k = 0
end
SeccompTools::Instruction::RET.new(OpenStruct.new(code: code, k: k))
SeccompTools::Instruction::RET.new(OpenStruct.new(code:, k:))
end

# ld A, immi
Expand Down Expand Up @@ -68,9 +68,9 @@

it 'args' do
args = [0, 0, 0, 0, 0, 0]
expect(described_class.new(@insts, sys_nr: 4, args: args, arch: :amd64).run[:ret]).to be 0
expect(described_class.new(@insts, sys_nr: 4, args:, arch: :amd64).run[:ret]).to be 0
args = [0, 0, 0, 0, 0, 0x313373133731337]
expect(described_class.new(@insts, sys_nr: 4, args: args, arch: :amd64).run[:ret]).to be 0x7fff0000
expect(described_class.new(@insts, sys_nr: 4, args:, arch: :amd64).run[:ret]).to be 0x7fff0000
end
end

Expand Down

0 comments on commit 6b4777b

Please sign in to comment.