HomeFreeBSD

MFC r337504: apply(1): Fix magic number substitution with a magic space

Description

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

Details

Provenance
kevansAuthored on
Parents
rS337824: Flesh out a comment about what we're doing with read bias and trims.
Branches
Unknown
Tags
Unknown