Skip to content

Commit 0081672

Browse files
Configure Undefined Behaviour Sanitizer (#6290)
1 parent 589becb commit 0081672

File tree

11 files changed

+68
-32
lines changed

11 files changed

+68
-32
lines changed

.github/workflows/osrm-backend.yml

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ jobs:
6464
CXXCOMPILER: g++-9
6565
ENABLE_COVERAGE: ON
6666

67-
- name: gcc-9-debug-asan
67+
- name: gcc-9-debug-asan-ubsan
6868
continue-on-error: false
6969
node: 12
7070
runs-on: ubuntu-20.04
@@ -74,7 +74,9 @@ jobs:
7474
CUCUMBER_TIMEOUT: 20000
7575
CXXCOMPILER: g++-9
7676
ENABLE_SANITIZER: ON
77-
TARGET_ARCH: x86_64-asan
77+
TARGET_ARCH: x86_64-asan-ubsan
78+
OSRM_CONNECTION_RETRIES: 10
79+
OSRM_CONNECTION_EXP_BACKOFF_COEF: 1.5
7880

7981
- name: clang-5.0-debug
8082
continue-on-error: false
@@ -95,13 +97,13 @@ jobs:
9597
CUCUMBER_TIMEOUT: 60000
9698
ENABLE_CLANG_TIDY: ON
9799

98-
- name: conan-linux-debug-asan
100+
- name: conan-linux-debug-asan-ubsan
99101
continue-on-error: false
100102
node: 12
101103
runs-on: ubuntu-20.04
102104
BUILD_TOOLS: ON
103105
BUILD_TYPE: Release
104-
CLANG_VERSION: 5.0.0
106+
CLANG_VERSION: 11.0.0
105107
ENABLE_CONAN: ON
106108
ENABLE_SANITIZER: ON
107109

@@ -382,6 +384,8 @@ jobs:
382384
ENABLE_SANITIZER: ${{ matrix.ENABLE_SANITIZER }}
383385
NODE_PACKAGE_TESTS_ONLY: ${{ matrix.NODE_PACKAGE_TESTS_ONLY }}
384386
TARGET_ARCH: ${{ matrix.TARGET_ARCH }}
387+
OSRM_CONNECTION_RETRIES: ${{ matrix.OSRM_CONNECTION_RETRIES }}
388+
OSRM_CONNECTION_EXP_BACKOFF_COEF: ${{ matrix.OSRM_CONNECTION_EXP_BACKOFF_COEF }}
385389
steps:
386390
- uses: actions/checkout@v2
387391

@@ -429,6 +433,7 @@ jobs:
429433
if [[ "$ENABLE_SANITIZER" == 'ON' ]]; then
430434
# We can only set this after checkout once we know the workspace directory
431435
echo "LSAN_OPTIONS=print_suppressions=0:suppressions=${GITHUB_WORKSPACE}/scripts/ci/leaksanitizer.conf" >> $GITHUB_ENV
436+
echo "UBSAN_OPTIONS=symbolize=1:halt_on_error=1:print_stacktrace=1:suppressions=${GITHUB_WORKSPACE}/scripts/ci/undefinedsanitizer.conf" >> $GITHUB_ENV
432437
fi
433438
434439
if [[ "${RUNNER_OS}" == "Linux" ]]; then
@@ -562,6 +567,12 @@ jobs:
562567
if: ${{ matrix.NODE_PACKAGE_TESTS_ONLY == 'ON' }}
563568
run: |
564569
npm run nodejs-tests
570+
- name: Upload test logs
571+
uses: actions/upload-artifact@v3
572+
if: failure()
573+
with:
574+
name: logs
575+
path: test/logs/
565576

566577
- name: Generate code coverage
567578
if: ${{ matrix.ENABLE_COVERAGE == 'ON' }}

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- Misc:
66
- FIXED: Fix bug with reading Set values from Lua scripts. [#6285](https://github.com/Project-OSRM/osrm-backend/pull/6285)
77
- Build:
8+
- CHANGED: Configure Undefined Behaviour Sanitizer. [#6290](https://github.com/Project-OSRM/osrm-backend/pull/6290)
89
- CHANGED: Use Conan instead of Mason to install code dependencies. [#6284](https://github.com/Project-OSRM/osrm-backend/pull/6284)
910
- CHANGED: Migrate to C++17. Update sol2 to 3.3.0. [#6279](https://github.com/Project-OSRM/osrm-backend/pull/6279)
1011
- CHANGED: Update macOS CI image to macos-11. [#6286](https://github.com/Project-OSRM/osrm-backend/pull/6286)

CMakeLists.txt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -316,11 +316,14 @@ if (ENABLE_COVERAGE)
316316
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -ftest-coverage -fprofile-arcs")
317317
endif()
318318

319+
319320
if (ENABLE_SANITIZER)
320-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
321-
set(OSRM_CXXFLAGS "${OSRM_CXXFLAGS} -fsanitize=address")
322-
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
323-
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=address")
321+
set(SANITIZER_FLAGS "-g -fsanitize=address -fsanitize-address-use-after-scope -fsanitize=undefined -fno-omit-frame-pointer")
322+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SANITIZER_FLAGS}")
323+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SANITIZER_FLAGS}")
324+
set(OSRM_CXXFLAGS "${OSRM_CXXFLAGS} ${SANITIZER_FLAGS}")
325+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${SANITIZER_FLAGS}")
326+
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${SANITIZER_FLAGS}")
324327
endif()
325328

326329
# Configuring compilers

features/lib/osrm_loader.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,12 @@ class OSRMBaseLoader{
4545
var retryCount = 0;
4646
let retry = (err) => {
4747
if (err) {
48-
if (retryCount < 10) {
48+
if (retryCount < this.scope.OSRM_CONNECTION_RETRIES) {
49+
const timeoutMs = 10 * Math.pow(this.scope.OSRM_CONNECTION_EXP_BACKOFF_COEF, retryCount);
4950
retryCount++;
50-
setTimeout(() => { tryConnect(this.scope.OSRM_IP, this.scope.OSRM_PORT, retry); }, 10);
51+
setTimeout(() => { tryConnect(this.scope.OSRM_IP, this.scope.OSRM_PORT, retry); }, timeoutMs);
5152
} else {
52-
callback(new Error("Could not connect to osrm-routed after ten retries."));
53+
callback(new Error(`Could not connect to osrm-routed after ${this.scope.OSRM_CONNECTION_RETRIES} retries.`));
5354
}
5455
}
5556
else

features/support/env.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ module.exports = function () {
4040

4141
this.OSRM_PORT = process.env.OSRM_PORT && parseInt(process.env.OSRM_PORT) || 5000;
4242
this.OSRM_IP = process.env.OSRM_IP || '127.0.0.1';
43+
this.OSRM_CONNECTION_RETRIES = process.env.OSRM_CONNECTION_RETRIES && parseInt(process.env.OSRM_CONNECTION_RETRIES) || 10;
44+
this.OSRM_CONNECTION_EXP_BACKOFF_COEF = process.env.OSRM_CONNECTION_EXP_BACKOFF_COEF && parseFloat(process.env.OSRM_CONNECTION_EXP_BACKOFF_COEF) || 1.0;
45+
4346
this.HOST = `http://${this.OSRM_IP}:${this.OSRM_PORT}`;
4447

4548
this.OSRM_PROFILE = process.env.OSRM_PROFILE;

include/contractor/contractor_config.hpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,8 @@ namespace contractor
4343
struct ContractorConfig final : storage::IOConfig
4444
{
4545
ContractorConfig()
46-
: IOConfig({".osrm.ebg", ".osrm.ebg_nodes", ".osrm.properties"},
47-
{},
48-
{".osrm.hsgr", ".osrm.enw"}),
49-
requested_num_threads(0)
46+
: IOConfig(
47+
{".osrm.ebg", ".osrm.ebg_nodes", ".osrm.properties"}, {}, {".osrm.hsgr", ".osrm.enw"})
5048
{
5149
}
5250

@@ -62,16 +60,16 @@ struct ContractorConfig final : storage::IOConfig
6260
updater::UpdaterConfig updater_config;
6361

6462
// DEPRECATED to be removed in v6.0
65-
bool use_cached_priority;
63+
bool use_cached_priority = false;
6664

67-
unsigned requested_num_threads;
65+
unsigned requested_num_threads = 0;
6866

6967
// DEPRECATED to be removed in v6.0
7068
// A percentage of vertices that will be contracted for the hierarchy.
7169
// Offers a trade-off between preprocessing and query time.
7270
// The remaining vertices form the core of the hierarchy
7371
//(e.g. 0.8 contracts 80 percent of the hierarchy, leaving a core of 20%)
74-
double core_factor;
72+
double core_factor = 1.0;
7573
};
7674
} // namespace contractor
7775
} // namespace osrm

include/engine/trip/trip_farthest_insertion.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,14 @@ GetShortestRoundTrip(const NodeID new_loc,
4848

4949
const auto dist_from = dist_table(*from_node, new_loc);
5050
const auto dist_to = dist_table(new_loc, *to_node);
51-
const auto trip_dist = dist_from + dist_to - dist_table(*from_node, *to_node);
52-
5351
// If the edge_weight is very large (INVALID_EDGE_WEIGHT) then the algorithm will not choose
5452
// this edge in final minimal path. So instead of computing all the permutations after this
5553
// large edge, discard this edge right here and don't consider the path after this edge.
5654
if (dist_from == INVALID_EDGE_WEIGHT || dist_to == INVALID_EDGE_WEIGHT)
5755
continue;
56+
57+
const auto trip_dist = dist_from + dist_to - dist_table(*from_node, *to_node);
58+
5859
// This is not neccessarily true:
5960
// Lets say you have an edge (u, v) with duration 100. If you place a coordinate exactly in
6061
// the middle of the segment yielding (u, v'), the adjusted duration will be 100 * 0.5 = 50.

include/extractor/extractor_config.hpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ struct ExtractorConfig final : storage::IOConfig
6969
".osrm.icd",
7070
".osrm.cnbg",
7171
".osrm.cnbg_to_ebg",
72-
".osrm.maneuver_overrides"}),
73-
requested_num_threads(0), parse_conditionals(false), use_locations_cache(true)
72+
".osrm.maneuver_overrides"})
7473
{
7574
}
7675

@@ -84,14 +83,12 @@ struct ExtractorConfig final : storage::IOConfig
8483
std::vector<boost::filesystem::path> location_dependent_data_paths;
8584
std::string data_version;
8685

87-
unsigned requested_num_threads;
88-
unsigned small_component_size;
86+
unsigned requested_num_threads = 0;
87+
unsigned small_component_size = 1000;
8988

90-
bool generate_edge_lookup;
91-
92-
bool use_metadata;
93-
bool parse_conditionals;
94-
bool use_locations_cache;
89+
bool use_metadata = false;
90+
bool parse_conditionals = false;
91+
bool use_locations_cache = true;
9592
};
9693
} // namespace extractor
9794
} // namespace osrm

include/util/log.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ class Log
8585
return *this;
8686
}
8787

88+
private:
89+
void Init();
90+
8891
protected:
8992
const LogLevel level;
9093
std::ostringstream buffer;

scripts/ci/undefinedsanitizer.conf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
enum:include/tbb/pipeline.h
2+
vptr:src/util/log.cpp
3+
vptr:include/tbb/task.h
4+
vptr:include/tbb/parallel_reduce.h
5+
vptr:include/boost/smart_ptr/detail/shared_count.hpp
6+
vptr:include/boost/smart_ptr/detail/sp_counted_base_gcc_atomic.hpp
7+
vptr:include/boost/program_options/variables_map.hpp
8+
vptr:include/boost/program_options/value_semantic.hpp
9+
vptr:src/tools/contract.cpp
10+
vptr:src/tools/extract.cpp
11+
pointer-overflow:include/partitioner/cell_storage.hpp
12+
signed-integer-overflow:include/engine/internal_route_result.hpp
13+
pointer-overflow:third_party/sol2/sol/stack_core.hpp
14+
pointer-overflow:third_party/rapidjson/include/rapidjson/internal/stack.h
15+
nonnull-attribute:third_party/microtar/src/microtar.c
16+
integer-divide-by-zero:unit_tests/library/route.cpp

0 commit comments

Comments
 (0)