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

[6.1.0]Remove O1 from sanitizer feature flag defaults #17439

Merged
merged 4 commits into from
Feb 8, 2023
Merged

[6.1.0]Remove O1 from sanitizer feature flag defaults #17439

merged 4 commits into from
Feb 8, 2023

Conversation

ShreeM01
Copy link
Contributor

@ShreeM01 ShreeM01 commented Feb 7, 2023

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

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
@ShreeM01 ShreeM01 enabled auto-merge (squash) February 7, 2023 22:10
@sgowroji sgowroji added team-Rules-CPP Issues for C++ rules awaiting-review PR is awaiting review from an assigned reviewer labels Feb 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-review PR is awaiting review from an assigned reviewer team-Rules-CPP Issues for C++ rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants