samtools / htslib

C library for high-throughput sequencing data formats
Other
809 stars 446 forks source link

Ensure strings in config_vars.h are escaped correctly #1530

Closed daviesrob closed 1 year ago

daviesrob commented 1 year ago

This is more tricky than it first appears as the strings in question have to make it through make expansion, shell string expansion, interpretation by the command writing the file, and end up making sense to the C compiler.

The values are escaped by converting \ to \\, " to \" and ' to \x27 (as it's impossible to quote a ' in a single-quoted string). Writing the file is now done by printf, which won't try to interpret any of the strings being printed as an option. Its arguments are all single-quoted to prevent the shell from trying to expand them in an unwanted manner.

Fixes #1527

jkbonfield commented 1 year ago

I'm a bit uneasy about requiring a command-line printf tool, but it seems to be a defined part of the POSIX environment so I assume it's now everywhere that sed, awk, etc are. Certainly for our own CI.