Skip to main content
added 11 characters in body
Source Link
Stéphane Chazelas
  • 586.5k
  • 96
  • 1.1k
  • 1.7k

You've got a vulnerability when there's a path for privilege escalation, that is when someone (let's call him the attacker) is able to do something he isthey are not meant to.

Most people will bump into bugs associated with unquoted variables because of the split part (for instance, it's common for files to have spaces in their names nowadays and space is in the default value of IFS$IFS). Many people will overlook the glob part. The glob part is at least as dangerous as the split part.

Arbitrary code execution is the worst type of vulnerability, since if the attacker can run any command, there's no limit on what hethey may do.

And with a $1 with value (IFS=-1234567890), that arithmetic evaluation has the side effect of settings IFS$IFS and the next [ command fails which means the check for too many args is bypassed.

You've got a vulnerability when there's a path for privilege escalation, that is when someone (let's call him the attacker) is able to do something he is not meant to.

Most people will bump into bugs associated with unquoted variables because of the split part (for instance, it's common for files to have spaces in their names nowadays and space is in the default value of IFS). Many people will overlook the glob part. The glob part is at least as dangerous as the split part.

Arbitrary code execution is the worst type of vulnerability, since if the attacker can run any command, there's no limit on what he may do.

And with a $1 with value (IFS=-1234567890), that arithmetic evaluation has the side effect of settings IFS and the next [ command fails which means the check for too many args is bypassed.

You've got a vulnerability when there's a path for privilege escalation, that is when someone (let's call him the attacker) is able to do something they are not meant to.

Most people will bump into bugs associated with unquoted variables because of the split part (for instance, it's common for files to have spaces in their names nowadays and space is in the default value of $IFS). Many people will overlook the glob part. The glob part is at least as dangerous as the split part.

Arbitrary code execution is the worst type of vulnerability, since if the attacker can run any command, there's no limit on what they may do.

And with a $1 with value (IFS=-1234567890), that arithmetic evaluation has the side effect of settings $IFS and the next [ command fails which means the check for too many args is bypassed.

deleted 2 characters in body
Source Link
Stéphane Chazelas
  • 586.5k
  • 96
  • 1.1k
  • 1.7k

In most shells, leaving a variable expansion unquoted (though that (and the rest of this answer) also applies to command substitution (`...` or $(...)) and arithmetic expansion ($((...)) or $[...])) has a very special meaning. The bestA good way to describe it is that it is like invoking some sort of implicit split+glob operator¹.

In most shells, leaving a variable expansion unquoted (though that (and the rest of this answer) also applies to command substitution (`...` or $(...)) and arithmetic expansion ($((...)) or $[...])) has a very special meaning. The best way to describe it is that it is like invoking some sort of implicit split+glob operator¹.

In most shells, leaving a variable expansion unquoted (though that (and the rest of this answer) also applies to command substitution (`...` or $(...)) and arithmetic expansion ($((...)) or $[...])) has a very special meaning. A good way to describe it is that it is like invoking some sort of implicit split+glob operator¹.

added 770 characters in body
Source Link
Stéphane Chazelas
  • 586.5k
  • 96
  • 1.1k
  • 1.7k

There are a few places though where quotes are not accepted. The main one being inside Korn-style arithmetic expressions in many shells like in echo "$(( $1 + 1 ))" "${array[$1 + 1]}" "${var:$1 + 1}" where the $1 must not be quoted (being in a list context --the arguments to a simple command-- the overall expansions still needs to be quoted though).

Inside those, the shell understands a separate language altogether inspired from C. In AT&T ksh for instance $(( 'd' - 'a' )) expands to 3 like it does in C and not the same as $(( d - a )) would. Double quotes are ignored in ksh93 but cause a syntax error in many other shells. In C, "d" - "a" would return the difference between pointers to C strings. Doing the same in shell would not make sense.

There are a few places though where quotes are not accepted. The main one being inside Korn-style arithmetic expressions in many shells like in echo "$(( $1 + 1 ))" "${array[$1 + 1]}" "${var:$1 + 1}" where the $1 must not be quoted (being in a list context --the arguments to a simple command-- the overall expansions still needs to be quoted though).

Inside those, the shell understands a separate language altogether inspired from C. In AT&T ksh for instance $(( 'd' - 'a' )) expands to 3 like it does in C and not the same as $(( d - a )) would. Double quotes are ignored in ksh93 but cause a syntax error in many other shells. In C, "d" - "a" would return the difference between pointers to C strings. Doing the same in shell would not make sense.

added 2 characters in body
Source Link
Stéphane Chazelas
  • 586.5k
  • 96
  • 1.1k
  • 1.7k
Loading
added 69 characters in body
Source Link
Stéphane Chazelas
  • 586.5k
  • 96
  • 1.1k
  • 1.7k
Loading
added 962 characters in body
Source Link
Stéphane Chazelas
  • 586.5k
  • 96
  • 1.1k
  • 1.7k
Loading
added 291 characters in body
Source Link
Stéphane Chazelas
  • 586.5k
  • 96
  • 1.1k
  • 1.7k
Loading
added 842 characters in body
Source Link
Stéphane Chazelas
  • 586.5k
  • 96
  • 1.1k
  • 1.7k
Loading
added 3 characters in body
Source Link
Stéphane Chazelas
  • 586.5k
  • 96
  • 1.1k
  • 1.7k
Loading
added 31 characters in body
Source Link
Stéphane Chazelas
  • 586.5k
  • 96
  • 1.1k
  • 1.7k
Loading
added 74 characters in body
Source Link
Stéphane Chazelas
  • 586.5k
  • 96
  • 1.1k
  • 1.7k
Loading
added 3 characters in body
Source Link
Stéphane Chazelas
  • 586.5k
  • 96
  • 1.1k
  • 1.7k
Loading
added 219 characters in body
Source Link
Stéphane Chazelas
  • 586.5k
  • 96
  • 1.1k
  • 1.7k
Loading
added 9 characters in body
Source Link
Stéphane Chazelas
  • 586.5k
  • 96
  • 1.1k
  • 1.7k
Loading
added 16 characters in body
Source Link
Stéphane Chazelas
  • 586.5k
  • 96
  • 1.1k
  • 1.7k
Loading
removed the "especially on Linux" bit. From a test, it's about as bad on FreeBSD.
Source Link
Stéphane Chazelas
  • 586.5k
  • 96
  • 1.1k
  • 1.7k
Loading
added 51 characters in body
Source Link
Stéphane Chazelas
  • 586.5k
  • 96
  • 1.1k
  • 1.7k
Loading
avoid http links
Source Link
Stéphane Chazelas
  • 586.5k
  • 96
  • 1.1k
  • 1.7k
Loading
Add link to "Are quotes needed for local variable assignment?"
Source Link
Wildcard
  • 37.5k
  • 30
  • 149
  • 284
Loading
deleted 2 characters in body
Source Link
Stéphane Chazelas
  • 586.5k
  • 96
  • 1.1k
  • 1.7k
Loading
added 7 characters in body
Source Link
Stéphane Chazelas
  • 586.5k
  • 96
  • 1.1k
  • 1.7k
Loading
at&t server down, replace with link to web archive
Source Link
Stéphane Chazelas
  • 586.5k
  • 96
  • 1.1k
  • 1.7k
Loading
added 9 characters in body
Source Link
Stéphane Chazelas
  • 586.5k
  • 96
  • 1.1k
  • 1.7k
Loading
added 6 characters in body
Source Link
Stéphane Chazelas
  • 586.5k
  • 96
  • 1.1k
  • 1.7k
Loading
typo
Source Link
Stéphane Chazelas
  • 586.5k
  • 96
  • 1.1k
  • 1.7k
Loading