Skip to content

Commit

Permalink
Updates handling of arm for both PostgreSQL and MySQL
Browse files Browse the repository at this point in the history
  • Loading branch information
cgranleese-r7 committed Apr 19, 2024
1 parent c694522 commit b83f2e3
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
8 changes: 6 additions & 2 deletions lib/postgres/postgres-pr/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,11 @@ def map_compile_arch_to_architecture(compile_arch)
elsif compile_arch.include?('ppc')
arch = ARCH_PPC
elsif compile_arch.match?('arm')
arch = ARCH_ARMLE
if compile_arch.match?('64')
arch = ARCH_AARCH64
elsif compile_arch.match?('arm')
arch = ARCH_ARMLE
end
elsif compile_arch.match?('64')
arch = ARCH_X86_64
elsif compile_arch.match?('86') || compile_arch.match?('i686')
Expand All @@ -209,7 +213,7 @@ def map_compile_arch_to_architecture(compile_arch)
def detect_platform_and_arch
result = {}

query_result = query('select version()').rows.join.match(/on (?<architecture>\w+)-\w+-(?<platform>\w+)-\w+/)
query_result = query('select version()').rows.join.match(/on (?<architecture>\w+)-\w+-(?<platform>\w+)/)
server_vars = {
'version_compile_machine' => query_result[:architecture],
'version_compile_os' => query_result[:platform]
Expand Down
6 changes: 5 additions & 1 deletion lib/rex/proto/mysql/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ def map_compile_arch_to_architecture(compile_arch)
arch = ARCH_SPARC
end
elsif compile_arch.match?('arm')
arch = ARCH_AARCH64
if compile_arch.match?('64')
arch = ARCH_AARCH64
elsif compile_arch.match?('arm')
arch = ARCH_ARMLE
end
elsif compile_arch.match?('64')
arch = ARCH_X86_64
elsif compile_arch.match?('86') || compile_arch.match?('i686')
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/rex/proto/mysql/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
{ info: '86', expected: ARCH_X86 },
{ info: 'i686', expected: ARCH_X86 },
{ info: 'arm64', expected: ARCH_AARCH64 },
{ info: 'arm', expected: ARCH_AARCH64 },
{ info: 'arm', expected: ARCH_ARMLE },
{ info: 'sparc', expected: ARCH_SPARC },
{ info: 'sparc64', expected: ARCH_SPARC64 },
{ info: '', expected: '' },
Expand Down
1 change: 1 addition & 0 deletions spec/lib/rex/proto/postgresql/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
[
{ version: 'PostgreSQL 9.4.26 on x86_64-pc-linux-gnu (Debian 9.4.26-1.pgdg90+1), compiled by gcc (Debian 6.3.0-18+deb9u1) 6.3.0 20170516, 64-bit', expected: { arch: 'x86_64', platform: 'Linux' } },
{ version: 'PostgreSQL 14.11 (Debian 14.11-1.pgdg120+2) on x86_64-pc-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit', expected: { arch: 'x86_64', platform: 'Linux' } },
{ version: 'PostgreSQL 14.11 (Homebrew) on x86_64-apple-darwin22.6.0, compiled by Apple clang version 15.0.0 (clang-1500.1.0.2.5), 64-bit', expected: { arch: 'x86_64', platform: 'OSX' } }
].each do |test|
context "when the database is version #{test[:version]}" do
it "returns #{test[:expected]}" do
Expand Down

0 comments on commit b83f2e3

Please sign in to comment.