Ticket #1622 (closed defect: fixed)

Opened 11 years ago

Last modified 10 years ago

bash -c crashes without $PWD

Reported by: hah Owned by: openmoko-kernel
Priority: normal Milestone:
Component: kernel Version:
Severity: normal Keywords: bash segfault crash PWD ssh scp default shell
Cc: moko@… Blocked By:
Blocking: Estimated Completion (week):
HasPatchForReview: PatchReviewResult:
Reproducible:

Description

Description of the bug:
Bash segfaults when it is invoked with -c and the environment variable PWD is not set.

Demonstration of the problem:
In /bin/sh (busybox):

~ # bash --version
GNU bash, version 3.2.33(1)-release (arm-angstrom-linux-gnueabi)
Copyright (C) 2007 Free Software Foundation, Inc.
~ # bash -c 'echo hi'
hi
~ # unset PWD
~ # bash -c 'echo hi'
Segmentation fault (core dumped)

One practical implication:
When using /bin/bash as the default shell (configured in /etc/passwd), ssh works fine, but scp and "ssh <host> <remote-command>" fails.
The ssh daemon does not seem to set $PWD, and scp and "ssh <host> <remote-command>" presumably cause "bash -c <command>" to be invoked.

Quick-fix script "/bin/bash-fixed":

#!/bin/sh
export PWD
exec /bin/bash "$@"

Change History

comment:1 Changed 11 years ago by drscream

  • Cc moko@… added

comment:2 Changed 11 years ago by hah

Quick-fix script "/bin/bash-fixed", version 2:

#!/bin/sh
export PWD
if tty | grep -q '/dev/pts/'; then
  exec /bin/bash --login "$@"
else
  exec /bin/bash "$@"
fi

Previous version of the script did not start a proper login-shell. Probably because argument zero is not passed to /bin/bash. From man bash:

A login shell is one whose first character of argument
zero is a -, or one started with the --login option.

With the old script, PATH was not exported, causing opkg to segfault:

# opkg upgrade
Segmentation fault

comment:3 Changed 10 years ago by graeme

  • Status changed from new to closed
  • Resolution set to fixed

This appears to be fixed in the latest bash version.

GNU bash, version 3.2.39(1)-release (arm-angstrom-linux-gnueabi)

I cannot trigger the problem and scp works fine with bash as the default shell.

Please re-open if you retest and its still broken.

Note: See TracTickets for help on using tickets.