tags:

views:

32

answers:

2

I have a PHP script which calls another script in order to add IP addresses to a whitelist. I sometimes want to whitelist all addresses, in which case I have it call

exec("otherscript *.*.*.*", output, retval);

This worked fine, adding the string "*.*.*.*" to the whitelist until I happened to have another file in the directory of the php script that matched that pattern ("foo.1.tar.gz"), at which point the wildcards were expanded, and I ended up with the filename in my whitelist. Is there some way to disable globbing in php's exec? It isn't mentioned in the PHP docs as far as I can tell.

+1  A: 

Quoting the parameter should help:

exec("otherscript '*.*.*.*'", output, retval);
deceze
Also make sure your input string to otherscript is sanitized. This can lead to all sorts of security issues.
Yann Ramin
Looks like in the end this is what escapeshellarg does as well
wxs
+3  A: 

escapeshellarg will make sure your string is safe for using as a shell argument. Globbing is probably not mentioned in the manual because it's up to the shell, and also differs between different shells.

$address = escapeshellarg('*.*.*.*');
exec("otherscript $address", $output, $retval);
Emil Vikström
Sure, but the manual makes no mention of *any* sort of a shell.
Ignacio Vazquez-Abrams
Ignacio, I stand corrected! :-) However, the manual do have a big, red warning message about using escapeshellarg.
Emil Vikström