Skip to content

Commit

Permalink
ci: Try ASAN/UBSAN in CI (#1049)
Browse files Browse the repository at this point in the history
Fixes #1044.
  • Loading branch information
WillAyd authored Sep 12, 2023
1 parent 48eb1dd commit cfc1227
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/native-unix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ jobs:
matrix:
os: ["macos-latest", "ubuntu-latest"]
env:
# Sanitizer support
LD_PRELOAD: "$(gcc --print-file-name=libasan.so)"
# Required for macOS
# https://conda-forge.org/docs/maintainer/knowledge_base.html#newer-c-features-with-old-sdk
CXXFLAGS: "-D_LIBCPP_DISABLE_AVAILABILITY"
Expand Down
7 changes: 7 additions & 0 deletions c/cmake_modules/san-config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ if(${ADBC_USE_ASAN})
OR (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION
VERSION_GREATER "4.8"))
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -DADDRESS_SANITIZER")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -DADDRESS_SANITIZER")
else()
message(SEND_ERROR "Cannot use ASAN without clang or gcc >= 4.8")
endif()
Expand All @@ -46,11 +47,17 @@ if(${ADBC_USE_UBSAN})
set(CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} -fsanitize=undefined -fno-sanitize=alignment,vptr,function,float-divide-by-zero -fno-sanitize-recover=all"
)
set(CMAKE_C_FLAGS
"${CMAKE_C_FLAGS} -fsanitize=undefined -fno-sanitize=alignment,vptr,function,float-divide-by-zero -fno-sanitize-recover=all"
)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION
VERSION_GREATER_EQUAL "5.1")
set(CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} -fsanitize=undefined -fno-sanitize=alignment,vptr -fno-sanitize-recover=all"
)
set(CMAKE_C_FLAGS
"${CMAKE_C_FLAGS} -fsanitize=undefined -fno-sanitize=alignment,vptr -fno-sanitize-recover=all"
)
else()
message(SEND_ERROR "Cannot use UBSAN without clang or gcc >= 5.1")
endif()
Expand Down
18 changes: 12 additions & 6 deletions c/driver/common/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,16 +166,22 @@ void AppendErrorDetail(struct AdbcError* error, const char* key, const uint8_t*
return;
}

memcpy(new_keys, details->keys, sizeof(char*) * details->count);
free(details->keys);
if (details->keys != NULL) {
memcpy(new_keys, details->keys, sizeof(char*) * details->count);
free(details->keys);
}
details->keys = new_keys;

memcpy(new_values, details->values, sizeof(uint8_t*) * details->count);
free(details->values);
if (details->values != NULL) {
memcpy(new_values, details->values, sizeof(uint8_t*) * details->count);
free(details->values);
}
details->values = new_values;

memcpy(new_lengths, details->lengths, sizeof(size_t) * details->count);
free(details->lengths);
if (details->lengths != NULL) {
memcpy(new_lengths, details->lengths, sizeof(size_t) * details->count);
free(details->lengths);
}
details->lengths = new_lengths;

details->capacity = new_capacity;
Expand Down
5 changes: 3 additions & 2 deletions c/driver/sqlite/statement_reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ void StatementReaderSetError(struct StatementReader* reader) {
const char* msg = sqlite3_errmsg(reader->db);
// Reset here so that we don't get an error again in StatementRelease
(void)sqlite3_reset(reader->stmt);
strncpy(reader->error.message, msg, sizeof(reader->error.message));
strncpy(reader->error.message, msg, sizeof(reader->error.message) - 1);
reader->error.message[sizeof(reader->error.message) - 1] = '\0';
}

Expand Down Expand Up @@ -594,7 +594,8 @@ int StatementReaderGetNext(struct ArrowArrayStream* self, struct ArrowArray* out
reader->done = 1;
status = EIO;
if (error.release) {
strncpy(reader->error.message, error.message, sizeof(reader->error.message));
strncpy(reader->error.message, error.message,
sizeof(reader->error.message) - 1);
reader->error.message[sizeof(reader->error.message) - 1] = '\0';
error.release(&error);
}
Expand Down

0 comments on commit cfc1227

Please sign in to comment.