Skip to content

Fix issue with odd number of arguments for Hash - #13758

Open
hedrok wants to merge 1 commit into
hashicorp:mainfrom
hedrok:fix-sshd-options-parsing
Open

Fix issue with odd number of arguments for Hash#13758
hedrok wants to merge 1 commit into
hashicorp:mainfrom
hedrok:fix-sshd-options-parsing

Conversation

@hedrok

@hedrok hedrok commented Dec 9, 2025

Copy link
Copy Markdown

In case sshd -T | grep key returns some lines without spaces Hash creation in communicator.rb failed with ArgumentError "odd number of arguments for Hash".

As only "pubkeyacceptedalgorithms", "pubkeyacceptedkeytypes", "hostkeyalgorithms" are needed, change to ignore lines that have no space.

This fixes error:

/home/vyos/tasks/VD-2244-thread-starvation/vagrant/plugins/communicators/ssh/communicator.rb:879:in `[]': odd number of arguments for Has
h (ArgumentError)

        opts = Hash[*list.split("\n").map{|line| line.split(" ", 2)}.flatten]
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        from /home/vyos/tasks/VD-2244-thread-starvation/vagrant/plugins/communicators/ssh/communicator.rb:879:in `supported_key_types'
        from /home/vyos/tasks/VD-2244-thread-starvation/vagrant/plugins/communicators/ssh/communicator.rb:215:in `ready?'
        from /home/vyos/tasks/VD-2244-thread-starvation/vagrant/plugins/communicators/ssh/communicator.rb:91:in `block in wait_for_ready'
        from /home/vyos/.local/share/gem/ruby/3.3.0/gems/timeout-0.5.0/lib/timeout.rb:222:in `block in timeout'
        from /home/vyos/.local/share/gem/ruby/3.3.0/gems/timeout-0.5.0/lib/timeout.rb:38:in `handle_timeout'
        from /home/vyos/.local/share/gem/ruby/3.3.0/gems/timeout-0.5.0/lib/timeout.rb:231:in `timeout'
        from /home/vyos/tasks/VD-2244-thread-starvation/vagrant/plugins/communicators/ssh/communicator.rb:66:in `wait_for_ready'
        from /home/vyos/tasks/VD-2244-thread-starvation/vagrant/lib/vagrant/action/builtin/wait_for_communicator.rb:19:in `block in call'

I got it while trying to launch NixOS under Vagrant with https://github.com/nix-community/nixbox.git.

list in line 872 of communicator.rb ends with

"rekeylimit 0 0\npubkeyauthoptions none\n\e]0;\a"

I don't know yet where \e]0;\a came from, but anyway I think ignoring lines without spaces here is good idea.

In case `sshd -T | grep key` returns some lines without spaces
Hash creation in communicator.rb failed with ArgumentError
"odd number of arguments for Hash".

As only "pubkeyacceptedalgorithms", "pubkeyacceptedkeytypes",
"hostkeyalgorithms" are needed, change to ignore lines that have
no space.
@hedrok
hedrok requested a review from a team as a code owner December 9, 2025 08:03
@hashicorp-cla-app

hashicorp-cla-app Bot commented Dec 9, 2025

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@A-Helberg

A-Helberg commented Jan 20, 2026

Copy link
Copy Markdown

As mentioned this also happens if the output contains terminal escape sequences, eq. "\e]0;\a" in my case.
A naive solution is to gsub the input string

# OSC: ESC ] ... (BEL or ESC \)
.gsub(/\e\][^\a\e]*(?:\a|\e\\)/, "")
# CSI: ESC [ ... letter
.gsub(/\e\[[0-?]*[ -\/]*[@-~]/, "")

"\e]0;\a" is a sequence to set the terminal title

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants