Skip to content

Commit

Permalink
Remove O1 from sanitizer feature flag defaults (#17439)
Browse files Browse the repository at this point in the history
This PR removes `-O1` from the current set of sanitizer related feature flags defaults.

**Context and Repro**
1. Heap buffer overflow in the following code block is not caught by asan.

example.cc
```
#include <cstdlib>

int main(int argc, char **argv) {
  int *array = new int[100];
  array[0] = 0;
  int res = array[argc + 100];  // BOOM
  delete [] array;
  return res;
}
```
BUILD
```
cc_binary(
  name = 'example',
  srcs = ['example.cc'],
  features = ['asan'],
)
```
execute:
```
bazel run :example
```

**Expectation:**
Address sanitizer should detect and report heap buffer overflow.

But this doesn't happen in the above case. It is because of O1 being applied by default and since this is added at the last, it also overrides explicit copts passed(O0). It would be nice if the optimization level is a bit de-coupled from the default group here.

Closes #17355.

PiperOrigin-RevId: 507658773
Change-Id: I3aa4fb92a2dc271cbbedfc6f05e72a8a9b2aba09

Co-authored-by: Chirag Ramani <chirag.ramani7@gmail.com>
  • Loading branch information
ShreeM01 and chiragramani authored Feb 8, 2023
1 parent f9c918c commit 05eefa1
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 2 deletions.
1 change: 0 additions & 1 deletion tools/cpp/unix_cc_toolchain_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ def _sanitizer_feature(name = "", specific_compile_flags = [], specific_link_fla
actions = all_compile_actions,
flag_groups = [
flag_group(flags = [
"-O1",
"-fno-omit-frame-pointer",
"-fno-sanitize-recover=all",
] + specific_compile_flags),
Expand Down
1 change: 0 additions & 1 deletion tools/osx/crosstool/cc_toolchain_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2674,7 +2674,6 @@ def _impl(ctx):
flag_groups = [
flag_group(
flags = [
"-O1",
"-gline-tables-only",
"-fno-omit-frame-pointer",
"-fno-sanitize-recover=all",
Expand Down

0 comments on commit 05eefa1

Please sign in to comment.