sshping icon indicating copy to clipboard operation
sshping copied to clipboard

[bug] `Option set error` when host alias contains underscore `_`

Open Jerry-Terrasse opened this issue 11 months ago • 0 comments

Problem

I have a host definition in my ~/.ssh/config like this:

Host host_a
    HostName x.x.x.x
    User myuser

When I use sshping to test that host, I got:

$ sshping -v host_a
User: --not specified--
Host: host_a
Port: 22
Echo: cat > /dev/null
 Cfg: --default--

+++ Attempting connection to host_a:22
*** Option set error: Invalid argument in ssh_options_set
*** Cannot establish ssh session

It works well if I replace host_a with host-a in ~/.ssh/config

Possible Reason

In src/sshping.cxx:540:

    _CKERR(ssh_options_set(ses, SSH_OPTIONS_HOST, addr));

In src/config_parser.c:242 of libssh, the hostname is passed to a syntax checking:

    if (hostname != NULL) {
        *hostname = strndup(tok, endp - tok);
        if (*hostname == NULL) {
            goto error;
        }
        /* if not an ip, check syntax */
        rc = ssh_is_ipaddr(*hostname);
        if (rc == 0) {
            rc = ssh_check_hostname_syntax(*hostname); // here
            if (rc != SSH_OK) {
                goto error;
            }
        }
    }

This checking is made according to RFC1035 section 2.3.1, and underscore is not allowed in hostname. Therefore, Option set error is caused.

Should that syntax checking be applied to host alias ?

PS: ssh host_a works well.

Jerry-Terrasse avatar Feb 11 '25 12:02 Jerry-Terrasse