You are not logged in.

#1 2014-09-29 21:02:12

oliver
Member
Registered: 2007-12-12
Posts: 448

[solved] bash - is this a result of the shellshock patches?

... or just something I've never noticed before

$ cat weird.sh 
#!/usr/bin/bash

testfunc() {
  echo "test inside function $1"
}

echo "test outside function $1"
testfunc
$ ./weird.sh arg1
test outside function arg1
test inside function 
$ bash --version
GNU bash, version 4.3.26(1)-release (x86_64-unknown-linux-gnu)

I was expecting $1 to be returned from the function too (and it does work if I add $1 as a variable - i,e. ARG=$1)

Last edited by oliver (2014-09-29 21:21:29)

Offline

#2 2014-09-29 21:08:09

aiBo
Member
Registered: 2010-11-10
Posts: 50

Re: [solved] bash - is this a result of the shellshock patches?

Works as it always has. Function invocation resets the positional paramters to the passed arguments. So, since you didn't pass any arguments to the function, $1 is empty inside the function block.

See 'set' in the 'SHELL BUILTIN COMMANDS' section in the bash manual page.

Last edited by aiBo (2014-09-29 21:12:44)

Offline

#3 2014-09-29 21:21:53

WorMzy
Administrator
From: Scotland
Registered: 2010-06-16
Posts: 13,438
Website

Re: [solved] bash - is this a result of the shellshock patches?

oliver wrote:

just something I've never noticed before

This.

As aiBo explained, you're not passing anything to the function, so $1 is not set inside it.

To further elaborate on this, what would you expect the output of the following to be?:

$ cat weird.sh
#!/usr/bin/bash

testfunc() {
  echo "test inside function $1"
}

echo "test outside function $1"
testfunc abc

$ ./weird.sh arg1

Last edited by WorMzy (2014-09-29 21:22:59)


Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD

Making lemonade from lemons since 2015.

Offline

#4 2014-09-29 21:22:03

oliver
Member
Registered: 2007-12-12
Posts: 448

Re: [solved] bash - is this a result of the shellshock patches?

aiBo wrote:

Works as it always has. Function invocation resets the positional paramters to the passed arguments. So, since you didn't pass any arguments to the function, $1 is empty inside the function block.

See 'set' in the 'SHELL BUILTIN COMMANDS' section in the bash manual page.

Thanks!  Makes perfect sense now

Offline

#5 2014-09-29 21:26:54

oliver
Member
Registered: 2007-12-12
Posts: 448

Re: [solved] bash - is this a result of the shellshock patches?

WorMzy wrote:

To further elaborate on this, what would you expect the output of the following to be?:

yeah - I see what you mean and I appreciate the further elaboration

Offline

#6 2014-09-30 15:27:41

ezzetabi
Member
Registered: 2006-08-27
Posts: 947

Re: [solved] bash - is this a result of the shellshock patches?

I have been told this code show the vunerability:

$ env x='() { :;}; echo vulnerable' bash -c "echo this is a test"

Offline

Board footer

Powered by FluxBB