]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
MFC r337504: apply(1): Fix magic number substitution with a magic space
authorkevans <kevans@FreeBSD.org>
Wed, 15 Aug 2018 01:24:43 +0000 (01:24 +0000)
committerkevans <kevans@FreeBSD.org>
Wed, 15 Aug 2018 01:24:43 +0000 (01:24 +0000)
commit6e209d97191e0e40faec053ccb107f06f72372ca
treec67bccd549fca50de3fbf854650c42e7e38f7bf1
parent1bb90d01acca0d81bdecd26ec66f1c78470cff05
MFC r337504: apply(1): Fix magic number substitution with a magic space

Using a space as the magic character would result in problems if the command
started with a number:

- For a 'valid' number n, n < size of argv, it would erroneously get
  replaced with that argument; e.g. `apply -a ' ' -d 1rm x => `execxrm x`

- For an 'invalid' number n, n >= size of argv, it would segfault.
  e.g. `apply -a ' ' 2to3 test.py` would try to access argv[2]

This problem occurred because apply(1) would prepend "exec " to the command
string before doing the actual magic number replacements, so it would come
across "exec 2to3 1" and assume that the " 2" is also a magic number to be
replaced.

Re-work this to instead just append "exec " to the command sbuf and
workaround the ugliness. This also simplifies stuff in the process.

PR: 226948
usr.bin/apply/apply.c