Skip to content

Commit

Permalink
Fix wrong decompilation on same jump target optmization (#248)
Browse files Browse the repository at this point in the history
  • Loading branch information
david942j authored Dec 25, 2023
1 parent afed5cf commit 4f35cf8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/seccomp-tools/asm/compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def emit_ret(val)

def emit_cmp(cmp, jt, jf)
jop, jt, jf = convert_jmp_op(cmp, jt, jf)
return emit(:jmp, jop, 0, jt: 0, jf: 0, k: jt) if jop == :ja || jt == jf
return emit(:jmp, :none, 0, jt: 0, jf: 0, k: jt) if jop == :ja || jt == jf

val = cmp[1]
src = val.x? ? :x : :k
Expand Down
19 changes: 19 additions & 0 deletions spec/asm/compiler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,25 @@
A = arch
EOS
end

it 'optimizes jump targets' do
compiler = described_class.new(<<-EOS, nil, :amd64)
A = args[0]
X = A
if (A == X) goto out
else goto out
A = X
out: return ALLOW
EOS

expect(compiler.compile!.map(&:decompile).join("\n")).to eq <<-EOS.strip
A = args[0]
X = A
goto 0004
A = X
return ALLOW
EOS
end
end

describe 'label' do
Expand Down

0 comments on commit 4f35cf8

Please sign in to comment.