618362d brp-mangle-shebangs: fix unsafe/incorrect command expansion

1 file Authored by vda 4 years ago, Committed by ignatenkobrain 4 years ago,
    brp-mangle-shebangs: fix unsafe/incorrect command expansion
    
    trim() {
      printf '%s' "$*"
    }
    ...
      read shebang_line < "$f" || :
      orig_shebang=$(trim $(echo "$shebang_line" | grep -Po "#!\K.*" || echo))
    
    The "trimming", i.e. replacement of multiple spaces and removal of leading
    and trailing spaces, is achieved because "trim $(cmd)" construct has an
    unquoted $(), which is subject to word splitting.
    
    This works, yes. BUT.
    
    It is also subject to glob expansion - any ?s and *s will be attempted
    to be expanded as well - definitely NOT what we want!
    
    This change replaces this trick with code which avoids the expansion issue,
    and which does not spawn any subprocesses for string manipulations -
    this is ~3 times faster (fork+execs are expensive).
    
    Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
    
        
file modified
+19 -14