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 clean compilation with -Wformat -Wformat=2 #2261

Merged
merged 1 commit into from
Sep 6, 2024

Conversation

daviesrob
Copy link
Member

Companion to samtools/htslib#1816, which among other things adds printf format checking attributes to bcf_hdr_printf(). This fixes a few places that could trigger warnings in bcftools as a result of that change. It also adds checking for some functions internal to bcftools so clang -Wformat -Wformat=2 works and fixes a couple of bugs that were found as a result.

Bugs fixed:

  • In open_file() a user-controlled string was passed as the format to mkdir_p(), which could lead to information leakage or possibly arbitrary writes via a crafted file path name.

  • Use of wrong type for position in vcfsort sort_blocks() error report.

  • Printing the wrong variable in vcfsort do_partial_merge() error report.

The -Wformat=2 option disallows non-literals in printf-like functions, which can be a little difficult to work around. Here most cases were fairly easy to sort out, apart from hdr_append() in plugins/fill-tags.c. For that the chosen solution was to convert the function into a macro. While not particularly nice it does allow all of the format strings passed in to be validated properly.

Adds Wformat to clang CI build to catch any future regressions.

Companion to samtools/htslib#1816, which among other things adds
printf format checking attributes to bcf_hdr_printf().  This fixes
a few places that could trigger warnings in bcftools as a result
of that change.  It also adds checking for some functions internal
to bcftools so `clang -Wformat -Wformat=2` works and fixes a couple
of bugs that were found as a result.

Bugs fixed:

 * In open_file() a user-controlled string was passed as the format
   to mkdir_p(), which could lead to information leakage or
   possibly arbitrary writes via a crafted file path name.

 * Use of wrong type for position in vcfsort sort_blocks() error report.

 * Printing the wrong variable in vcfsort do_partial_merge() error report.

The -Wformat=2 option disallows non-literals in printf-like
functions, which can be a little difficult to work around.  Here
most cases were fairly easy to sort out, apart from hdr_append()
in plugins/fill-tags.c.  For that the chosen solution was to
convert the function into a macro. While not particularly nice it
does allow all of the format strings passed in to be validated
properly.

Adds Wformat to clang CI build to catch any future regressions.
@pd3 pd3 merged commit 37f1600 into samtools:develop Sep 6, 2024
8 checks passed
@pd3
Copy link
Member

pd3 commented Sep 6, 2024

Thank you

@daviesrob daviesrob deleted the format-literals branch September 12, 2024 18:16
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.

2 participants