T
T
Trotil2014-06-06 08:58:38
linux
Trotil, 2014-06-06 08:58:38

Linux: binary name spoofing - what are the unpredictable consequences?

There is a complex chain of program calls (some processes start several other processes). There was a need to solve compatibility problems to perform some preliminary steps before running the progX
binary executable (which is not called by me, but by other processes). mv progX progX_orig Create your own progX:

#!/bin/sh

# некоторые действия: 
# обработка входных параметров, 
# установка дополнительных переменных окружения, 
# и т.д. ...

path_to_dir/progX_orig $*

This approach seems to work.
However, is this method completely transparent and OS safe?
Afterwards, is there a way to make an execve call in bash to minimize the differences? What happens if the child processes start looking for the parent process?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
dykky, 2014-06-06
@Trotil

1. This is an absolutely normal approach.
2. If the program call is the last action of the script, then it is better not to do a subprocess, but to replace the current process with a program, which saves some memory and preserves the parent-child relationship for signals (i.e. after the script is processed, the parent program will receive exactly the same state of the child process, as well as before replacing the program with a script):

#!/bin/sh

# некоторые действия: 
# обработка входных параметров, 
# установка дополнительных переменных окружения, 
# и т.д. ...

exec path_to_dir/progX_orig $*

3. It is better to pass the parameters to the program as they were passed to the script, and the $* construction will reparse the arguments.
Those. the last line, taking into account paragraph 2, in my opinion, should look like this
exec path_to_dir/progX_orig "[email protected]"

M
Mikhail Alekseev, 2014-06-06
@Fandorin

Depends on what the progX binary is and who else is using it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question