Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure strings in config_vars.h are escaped correctly #1530

Merged
merged 1 commit into from
Dec 5, 2022

Conversation

daviesrob
Copy link
Member

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

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.
@jkbonfield jkbonfield self-assigned this Nov 29, 2022
@jkbonfield
Copy link
Contributor

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.

@jkbonfield jkbonfield merged commit e88e343 into samtools:develop Dec 5, 2022
@daviesrob daviesrob deleted the config_vars branch December 6, 2022 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Preprocessor definitions with quotation marks
2 participants