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

Add undefined behaviour sanitizer into the CI checks #1816

Merged
merged 4 commits into from
Aug 19, 2024

Conversation

jkbonfield
Copy link
Contributor

Due to cirrus-ci lacking ubsan in the clang installation it needed a bit of juggling as to what checks are executed in which compiler, but this now allows us to automatically spot some undefined behaviour via the CI system.

@daviesrob daviesrob self-assigned this Aug 8, 2024
.cirrus.yml Outdated Show resolved Hide resolved
.cirrus.yml Show resolved Hide resolved
We already have address sanitizer, so add "undefined" into the mix.

We also have to tweak a few warnings when using ubsan.
Useful when diagnosing CI systems.
We lost level 2 when we swapped the sanitizers between ubuntu gcc and
clang, as Clang's -Wformat=2 is too spammy and we couldn't keep it on
gcc as it breaks the sanitizers.  So this puts it onto a third build
instead.
These are needed in newer clangs with -Wformat=2.
daviesrob added a commit to daviesrob/bcftools that referenced this pull request Aug 19, 2024
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.

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.
@daviesrob daviesrob merged commit 8e3ef4b into samtools:develop Aug 19, 2024
9 checks passed
daviesrob added a commit to daviesrob/bcftools that referenced this pull request Aug 19, 2024
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.

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.
daviesrob added a commit to daviesrob/bcftools that referenced this pull request Aug 19, 2024
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 pushed a commit to samtools/bcftools that referenced this pull request Sep 6, 2024
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.
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