Skip to content

cd override breaks for directories with spaces due to unquoted $* #546

Description

@kristianmondelez

Bug Description

The cd() override in scripts/env/cd fails when changing into directories that contain spaces in their path. The shell reports cd: too many arguments.

Root Cause

There are two locations where $* is used unquoted, causing word splitting on paths with spaces:

Line 23 - Definition of __gvm_oldcd:

eval "$(echo "__gvm_oldcd() { builtin cd \$*; return \$?; }")"

Line 49 - Invocation inside cd():

__gvm_oldcd $*

Steps to Reproduce

mkdir -p "/tmp/test dir with spaces"
cd "/tmp/test dir with spaces"
# Error: cd: too many arguments

Expected Behavior

cd "/tmp/test dir with spaces" should change into the directory successfully.

Proposed Fix

Replace the unquoted $* with quoted "$@" in both locations:

Line 23:

eval "$(echo "__gvm_oldcd() { builtin cd \"\$@\"; return \$?; }")"

Line 49:

__gvm_oldcd "$@"

Environment

  • GVM version: 1.0.22
  • OS: Linux (Ubuntu)
  • Shell: Bash

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions