I had a look at the code, and the way incron works is:
- Escape spaces and backslashes in the filename (
IncronTabEntry::GetSafePath
- Substitute the directory name, filename, etc. in the command line
- Run the processed command line using either
/bin/sh -c
(using system()
for the root user) or /bin/bash -c
(for normal users - UserTable::RunAsUser
)
In neither case is (
or )
safe to pass unescaped. (And not just these, but other special characters like ;
, *
, [
/]
, &&
, $( ... )
, etc.) This is a command injection vulnerability waiting to be exploited. See, e.g., this Unix & Linux post or this one for the pitfalls in embedding filenames directly into shell command strings. Arch Linux has a patch expanding the set of characters that are escaped which will solve your particular problem since it includes (
and )
, but still misses out on *
, ;
, |
, etc.
You can work around this somewhat by trying to quote the command line in the incrontab
:
/inputdir IN_ALL_EVENTS /root/jobs/monitor '$@' $% '$#'
But this will still fail for filenames with '
in them. All you can really do is file a bug report asking for more escaping, or ask them to use execve
and family to run the command directly instead of using system()
or running /bin/bash -c '...'
. The problem then is that they will have to parse the command line differently, splitting it into words, and implement an escaping mechanism, etc.