Bug 3158 - ssh-copy-id raises "expr: syntax error" when double-hyphen is passed ("--")
Summary: ssh-copy-id raises "expr: syntax error" when double-hyphen is passed ("--")
Status: CLOSED FIXED
Alias: None
Product: Portable OpenSSH
Classification: Unclassified
Component: ssh-copy-id (show other bugs)
Version: 8.2p1
Hardware: All Linux
: P5 minor
Assignee: Assigned to nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-05-04 07:51 AEST by rf
Modified: 2021-03-04 09:52 AEDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description rf 2020-05-04 07:51:19 AEST
Assuming an identity file exists at ~/.ssh/id_rsa.pub, the following command, which adds a preventative double-dash ("--"):

    ssh-copy-id -i ~/.ssh/id_rsa.pub -- remote-server

will result in the following error:

    expr: syntax error: unexpected argument ‘[-]i’

The error is non-fatal, but it may be confusing to users.

I suspect this is caused by line 110:

    [ "${SEEN_OPT_I}" ] && expr "$1" : "[-]i" >/dev/null && {

Here, "$1" is passed to expr without being validated, so if $1 is "--" as shown in the command above, this will confuse expr.  I think expr should be called with "--" to prevent this:

    [ "${SEEN_OPT_I}" ] && expr -- "$1" : "[-]i" >/dev/null && {
Comment 1 Philip Hands 2020-09-17 16:25:04 AEST
ssh-copy-id has switched to using getopts for this, rather than the previous hand-rolled option handling, so I beleive that once that version is included in openssh this problem will be solved.

Perhaps you'd be so kind as to check that -- you can find the latest version here:

  https://gitlab.com/phil_hands/ssh-copy-id

Cheers, Phil.
Comment 2 rf 2020-09-20 10:17:51 AEST
The issue appears to be fixe din the new ssh-copy-id. Thanks!
Comment 3 Damien Miller 2021-03-04 09:52:21 AEDT
close bugs that were resolved in OpenSSH 8.5 release cycle