From 2db898f884f9732520cfc9a8f9610510ce2af68b Mon Sep 17 00:00:00 2001 From: Khushi Kathuria Date: Thu, 7 May 2026 14:04:53 +0530 Subject: [PATCH 1/3] fix(bq_driver): Asan CI check fix --- .../builds/integration-bq-driver-asan.sh | 5 +-- .../ubuntu-22.04-install.Dockerfile | 33 +++++++------------ ci/gha/builds/lib/lsan.supp | 6 ++++ .../odbc_driver_tests/connection_test.cc | 8 +++-- 4 files changed, 27 insertions(+), 25 deletions(-) diff --git a/ci/cloudbuild/builds/integration-bq-driver-asan.sh b/ci/cloudbuild/builds/integration-bq-driver-asan.sh index 54bf4fd821..be73a7c737 100755 --- a/ci/cloudbuild/builds/integration-bq-driver-asan.sh +++ b/ci/cloudbuild/builds/integration-bq-driver-asan.sh @@ -42,7 +42,6 @@ git checkout "$VCPKG_VERSION" ./bootstrap-vcpkg.sh -disableMetrics cd "$WORKSPACE_DIR" - # This runs all the unit tests mapfile -t args < <(bazel::common_args) mapfile -t unit_tests_args < <(unit_tests::bazel_args) @@ -56,6 +55,7 @@ mapfile -t cmake_args < <(cmake::common_args) BUILD_DIR="/opt/odbc-driver" # This is the name of DSN set in odbc.ini export ODBC_TESTS_DSN="SampleDSNGoogleDriver" +export ASAN_OPTIONS="detect_container_overflow=0:detect_leaks=1" export LSAN_OPTIONS="use_tls=0:suppressions=/opt/odbc-driver/lsan.supp:print_suppressions=0" export CPP_BIGQUERY_ODBC_TEST_TABLE_PREFIX=${TRIGGER_NAME//[-:;.,?]/_}_${BRANCH_NAME//[-:;.,?]/_} @@ -84,8 +84,9 @@ io::run cmake -B "$BUILD_DIR" \ -DODBC_EXAMPLES=ON \ -DODBC_UNIT_TESTING=OFF \ -DCLIENT_LIBRARY_INTEGRATION_TESTING=OFF - io::run cmake --build cmake-out +# Copy the roots.pem file to the .so directory to run test cases. +cp /opt/odbc-driver/roots.pem "cmake-out/google/cloud/odbc/roots.pem" mapfile -t ctest_args < <(ctest::common_args) io::run env -C cmake-out ctest "${ctest_args[@]}" diff --git a/ci/cloudbuild/dockerfiles/ubuntu-22.04-install.Dockerfile b/ci/cloudbuild/dockerfiles/ubuntu-22.04-install.Dockerfile index 33e5f46c3f..13ba73141e 100644 --- a/ci/cloudbuild/dockerfiles/ubuntu-22.04-install.Dockerfile +++ b/ci/cloudbuild/dockerfiles/ubuntu-22.04-install.Dockerfile @@ -22,8 +22,7 @@ RUN apt-get update && \ build-essential \ # Dependency for arrow bison \ - clang-12 \ - lld-12 \ + clang \ cmake \ curl \ # Dependency for arrow @@ -32,10 +31,8 @@ RUN apt-get update && \ git \ gcc \ g++ \ - # Required by Ubsan in Ubuntu 22.04 - libunwind-12-dev \ - libc++-12-dev \ - libc++abi-12-dev \ + libc++-dev \ + libc++abi-dev \ libcurl4-openssl-dev \ # Needed to use autoreconf libltdl-dev \ @@ -61,7 +58,15 @@ RUN apt-get update && \ apt-utils \ ca-certificates \ apt-transport-https \ - clang-tidy-12 + clang-tidy + +# Set Clang 12 as default +RUN update-alternatives --install /usr/bin/cc cc /usr/bin/clang 100 && \ + update-alternatives --install /usr/bin/c++ c++ /usr/bin/clang++ 100 + +# Set the compiler environment variables +ENV CC=/usr/bin/clang +ENV CXX=/usr/bin/clang++ # Needed for the existing driver v3.1.2.1004+ RUN locale-gen en_US.UTF-8 @@ -69,20 +74,6 @@ ENV LANG en_US.UTF-8 ENV LANGUAGE en_US.UTF-8 ENV LC_ALL en_US.UTF-8 -# Set clang as default -RUN update-alternatives --install /usr/bin/clang clang /usr/bin/clang-12 100 && \ - update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-12 100 - -ENV CC=clang -ENV CXX=clang++ - -# Install modern CMake locally -RUN mkdir -p /opt/cmake && \ - curl -fsSL https://github.com/Kitware/CMake/releases/download/v3.30.1/cmake-3.30.1-linux-x86_64.tar.gz \ - | tar -xz --strip-components=1 -C /opt/cmake - -ENV PATH=/opt/cmake/bin:$PATH - # clang-tidy-cache needs python RUN update-alternatives --install /usr/bin/python python $(which python3) 10 diff --git a/ci/gha/builds/lib/lsan.supp b/ci/gha/builds/lib/lsan.supp index 37afd5d2a3..c60d360db1 100644 --- a/ci/gha/builds/lib/lsan.supp +++ b/ci/gha/builds/lib/lsan.supp @@ -7,3 +7,9 @@ leak:Diagnostics::AddStatusRecord leak:StatusRecord leak:std::__cxx11::basic_string leak:_iodbcdm_SetConnectOption_init +leak:ld-linux-x86-64.so.2 +leak:_dl_exception_create_format +leak:libc.so.6 +leak:CRYPTO_zalloc +leak:grpc_jwt_encode_and_sign +leak:_iodbcdm_pushsqlerr diff --git a/google/cloud/odbc/integration_tests/odbc_driver_tests/connection_test.cc b/google/cloud/odbc/integration_tests/odbc_driver_tests/connection_test.cc index 253438fdca..8fc6851f4d 100644 --- a/google/cloud/odbc/integration_tests/odbc_driver_tests/connection_test.cc +++ b/google/cloud/odbc/integration_tests/odbc_driver_tests/connection_test.cc @@ -1227,9 +1227,13 @@ TEST(ConnectionTest, SQLBrowseConnect_InvalidConnectionAttribute) { HasSubstr("Catalog:Catalog=?;OAuthMechanism:OAuthMechanism=?")); #endif // _WIN32 } - // Pass `false` to indicate that the Driver Manager (DM) will automatically - // free the environment handle when the last connection handle is released. +// Pass `false` to indicate that the Driver Manager (DM) will automatically +// free the environment handle when the last connection handle is released. +#ifdef _WIN32 CleanupODBCHandles(*conn, false); +#else + CleanupODBCHandles(*conn); +#endif } TEST(ConnectionTest, SQLBrowseConnect_InvalidConnectionString) { From 007d1e43b3339ad082ab9253b21309f23de031ff Mon Sep 17 00:00:00 2001 From: Neeraj Dwivedi Date: Wed, 10 Jun 2026 20:38:59 +0530 Subject: [PATCH 2/3] test chnages --- vcpkg.json | 1 - 1 file changed, 1 deletion(-) diff --git a/vcpkg.json b/vcpkg.json index dba31fd8fa..6122c1ecbc 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -30,7 +30,6 @@ }, { "name": "grpc", "version>=": "1.68.2" }, { "name": "opentelemetry-cpp", "version>=": "1.18.0" }, - { "name": "protobuf", "version>=": "5.29.2" }, "nlohmann-json", "benchmark", { "name": "gtest", "version>=": "1.15.2" } From dfdb06ecd70d86e0fab9461a86ec03d46f723f0a Mon Sep 17 00:00:00 2001 From: Anshu6250 Date: Mon, 27 Jul 2026 16:38:55 +0530 Subject: [PATCH 3/3] fix: asan git check --- CMakeLists.txt | 1 + .../builds/integration-bq-driver-asan.sh | 10 ++++-- .../ubuntu-22.04-install.Dockerfile | 33 ++++++++++++------- ci/cloudbuild/triplets/x64-linux-asan.cmake | 23 +++++++++++++ ci/gha/builds/lib/lsan.supp | 11 +++---- .../odbc_driver_tests/connection_test.cc | 9 ++--- .../driver_properties_test.cc | 3 ++ .../odbc_driver_tests/statement_test.cc | 6 ++++ vcpkg.json | 1 + 9 files changed, 70 insertions(+), 27 deletions(-) create mode 100644 ci/cloudbuild/triplets/x64-linux-asan.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 3245f9bc0c..4cf63f90f5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -51,6 +51,7 @@ if (ENABLE_SANITIZER) "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=address") + add_compile_definitions(ODBC_ADDRESS_SANITIZER) else () message(WARNING "AddressSanitizer is only supported on UNIX platforms") endif () diff --git a/ci/cloudbuild/builds/integration-bq-driver-asan.sh b/ci/cloudbuild/builds/integration-bq-driver-asan.sh index be73a7c737..9728d2745c 100755 --- a/ci/cloudbuild/builds/integration-bq-driver-asan.sh +++ b/ci/cloudbuild/builds/integration-bq-driver-asan.sh @@ -42,6 +42,7 @@ git checkout "$VCPKG_VERSION" ./bootstrap-vcpkg.sh -disableMetrics cd "$WORKSPACE_DIR" + # This runs all the unit tests mapfile -t args < <(bazel::common_args) mapfile -t unit_tests_args < <(unit_tests::bazel_args) @@ -55,8 +56,9 @@ mapfile -t cmake_args < <(cmake::common_args) BUILD_DIR="/opt/odbc-driver" # This is the name of DSN set in odbc.ini export ODBC_TESTS_DSN="SampleDSNGoogleDriver" -export ASAN_OPTIONS="detect_container_overflow=0:detect_leaks=1" -export LSAN_OPTIONS="use_tls=0:suppressions=/opt/odbc-driver/lsan.supp:print_suppressions=0" +export LSAN_OPTIONS="use_tls=0:suppressions=/opt/odbc-driver/lsan.supp:print_suppressions=0:fast_unwind_on_malloc=0" +ASAN_SYMBOLIZER_PATH="$(command -v llvm-symbolizer)" +export ASAN_SYMBOLIZER_PATH export CPP_BIGQUERY_ODBC_TEST_TABLE_PREFIX=${TRIGGER_NAME//[-:;.,?]/_}_${BRANCH_NAME//[-:;.,?]/_} @@ -76,6 +78,8 @@ fi io::run cmake -B "$BUILD_DIR" \ "${cmake_args[@]}" \ -DCMAKE_TOOLCHAIN_FILE="${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" \ + -DVCPKG_OVERLAY_TRIPLETS="${WORKSPACE_DIR}/ci/cloudbuild/triplets" \ + -DVCPKG_TARGET_TRIPLET=x64-linux-asan \ -DCMAKE_CXX_STANDARD=17 \ -DODBC_INTEGRATION_TESTING=ON \ -DBQ_DRIVER_INTEGRATION_TESTS=ON \ @@ -87,6 +91,6 @@ io::run cmake -B "$BUILD_DIR" \ io::run cmake --build cmake-out # Copy the roots.pem file to the .so directory to run test cases. -cp /opt/odbc-driver/roots.pem "cmake-out/google/cloud/odbc/roots.pem" +io::run cp /opt/odbc-driver/roots.pem "cmake-out/google/cloud/odbc/roots.pem" mapfile -t ctest_args < <(ctest::common_args) io::run env -C cmake-out ctest "${ctest_args[@]}" diff --git a/ci/cloudbuild/dockerfiles/ubuntu-22.04-install.Dockerfile b/ci/cloudbuild/dockerfiles/ubuntu-22.04-install.Dockerfile index 13ba73141e..33e5f46c3f 100644 --- a/ci/cloudbuild/dockerfiles/ubuntu-22.04-install.Dockerfile +++ b/ci/cloudbuild/dockerfiles/ubuntu-22.04-install.Dockerfile @@ -22,7 +22,8 @@ RUN apt-get update && \ build-essential \ # Dependency for arrow bison \ - clang \ + clang-12 \ + lld-12 \ cmake \ curl \ # Dependency for arrow @@ -31,8 +32,10 @@ RUN apt-get update && \ git \ gcc \ g++ \ - libc++-dev \ - libc++abi-dev \ + # Required by Ubsan in Ubuntu 22.04 + libunwind-12-dev \ + libc++-12-dev \ + libc++abi-12-dev \ libcurl4-openssl-dev \ # Needed to use autoreconf libltdl-dev \ @@ -58,15 +61,7 @@ RUN apt-get update && \ apt-utils \ ca-certificates \ apt-transport-https \ - clang-tidy - -# Set Clang 12 as default -RUN update-alternatives --install /usr/bin/cc cc /usr/bin/clang 100 && \ - update-alternatives --install /usr/bin/c++ c++ /usr/bin/clang++ 100 - -# Set the compiler environment variables -ENV CC=/usr/bin/clang -ENV CXX=/usr/bin/clang++ + clang-tidy-12 # Needed for the existing driver v3.1.2.1004+ RUN locale-gen en_US.UTF-8 @@ -74,6 +69,20 @@ ENV LANG en_US.UTF-8 ENV LANGUAGE en_US.UTF-8 ENV LC_ALL en_US.UTF-8 +# Set clang as default +RUN update-alternatives --install /usr/bin/clang clang /usr/bin/clang-12 100 && \ + update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-12 100 + +ENV CC=clang +ENV CXX=clang++ + +# Install modern CMake locally +RUN mkdir -p /opt/cmake && \ + curl -fsSL https://github.com/Kitware/CMake/releases/download/v3.30.1/cmake-3.30.1-linux-x86_64.tar.gz \ + | tar -xz --strip-components=1 -C /opt/cmake + +ENV PATH=/opt/cmake/bin:$PATH + # clang-tidy-cache needs python RUN update-alternatives --install /usr/bin/python python $(which python3) 10 diff --git a/ci/cloudbuild/triplets/x64-linux-asan.cmake b/ci/cloudbuild/triplets/x64-linux-asan.cmake new file mode 100644 index 0000000000..94014ae18b --- /dev/null +++ b/ci/cloudbuild/triplets/x64-linux-asan.cmake @@ -0,0 +1,23 @@ +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may not +# use this file except in compliance with the License. You may obtain a copy of +# the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations under +# the License. + +# Keep ASan-instrumented dependencies separate from the normal x64-linux +# binaries in vcpkg's binary cache. +set(VCPKG_TARGET_ARCHITECTURE x64) +set(VCPKG_CMAKE_SYSTEM_NAME Linux) +set(VCPKG_CRT_LINKAGE dynamic) +set(VCPKG_LIBRARY_LINKAGE static) +set(VCPKG_C_FLAGS "-O1 -fsanitize=address -fno-omit-frame-pointer -g") +set(VCPKG_CXX_FLAGS "-O1 -fsanitize=address -fno-omit-frame-pointer -g") +set(VCPKG_LINKER_FLAGS "-fsanitize=address") diff --git a/ci/gha/builds/lib/lsan.supp b/ci/gha/builds/lib/lsan.supp index c60d360db1..40a21ad569 100644 --- a/ci/gha/builds/lib/lsan.supp +++ b/ci/gha/builds/lib/lsan.supp @@ -2,14 +2,13 @@ leak:conv_text_m2d leak:__interceptor_malloc leak:__interceptor_calloc leak:_iodbcdm_driverload +leak:_iodbcdm_driverunload +leak:_iodbcdm_pushsqlerr +leak:grpc_jwt_encode_and_sign +leak:grpc_core::DoSslRead +leak:grpc_core::DoSslWrite leak:calloc leak:Diagnostics::AddStatusRecord leak:StatusRecord leak:std::__cxx11::basic_string leak:_iodbcdm_SetConnectOption_init -leak:ld-linux-x86-64.so.2 -leak:_dl_exception_create_format -leak:libc.so.6 -leak:CRYPTO_zalloc -leak:grpc_jwt_encode_and_sign -leak:_iodbcdm_pushsqlerr diff --git a/google/cloud/odbc/integration_tests/odbc_driver_tests/connection_test.cc b/google/cloud/odbc/integration_tests/odbc_driver_tests/connection_test.cc index 8fc6851f4d..b807fc7050 100644 --- a/google/cloud/odbc/integration_tests/odbc_driver_tests/connection_test.cc +++ b/google/cloud/odbc/integration_tests/odbc_driver_tests/connection_test.cc @@ -1227,13 +1227,7 @@ TEST(ConnectionTest, SQLBrowseConnect_InvalidConnectionAttribute) { HasSubstr("Catalog:Catalog=?;OAuthMechanism:OAuthMechanism=?")); #endif // _WIN32 } -// Pass `false` to indicate that the Driver Manager (DM) will automatically -// free the environment handle when the last connection handle is released. -#ifdef _WIN32 - CleanupODBCHandles(*conn, false); -#else CleanupODBCHandles(*conn); -#endif } TEST(ConnectionTest, SQLBrowseConnect_InvalidConnectionString) { @@ -1493,6 +1487,9 @@ TEST(SQLDisconnect, CheckAllHandlesAreFreed) { auto status = SQLAllocHandle(SQL_HANDLE_DESC, conn->hdbc, &conn->ard); CheckError(status, "SQLAllocHandle(SQL_HANDLE_DESC)", conn); + status = SQLFreeHandle(SQL_HANDLE_DESC, conn->ard); + CheckError(status, "SQLFreeHandle(SQL_HANDLE_DESC)", conn); + status = SQLDisconnect(conn->hdbc); CheckError(status, "SQLDisconnect", conn); diff --git a/google/cloud/odbc/integration_tests/odbc_driver_tests/driver_properties_test.cc b/google/cloud/odbc/integration_tests/odbc_driver_tests/driver_properties_test.cc index 7765422d06..798e590f5c 100644 --- a/google/cloud/odbc/integration_tests/odbc_driver_tests/driver_properties_test.cc +++ b/google/cloud/odbc/integration_tests/odbc_driver_tests/driver_properties_test.cc @@ -271,6 +271,9 @@ TEST(SQLGetTypeInfoTest, all_datatypes) { // reach this TEST // TODO(b/477506552): Fix memory issue in SQLGetTypeInfoTest bind offset TEST(SQLGetTypeInfoTest, all_datatypes_with_offset) { +#ifdef ODBC_ADDRESS_SANITIZER + GTEST_SKIP() << "The row-bind-offset test is not ASAN-safe."; +#endif #ifdef NDEBUG GTEST_SKIP(); #endif // NDEBUG diff --git a/google/cloud/odbc/integration_tests/odbc_driver_tests/statement_test.cc b/google/cloud/odbc/integration_tests/odbc_driver_tests/statement_test.cc index eadd203c8a..6f4ccf2002 100644 --- a/google/cloud/odbc/integration_tests/odbc_driver_tests/statement_test.cc +++ b/google/cloud/odbc/integration_tests/odbc_driver_tests/statement_test.cc @@ -830,6 +830,9 @@ TEST(StatementTest, SQLExecute_UsingDescriptor) { CheckError(status, "SQLAllocHandle", conn); EXPECT_EQ(InsertStatementWithoutBindParameter(conn), SQL_SUCCESS); + status = SQLFreeHandle(SQL_HANDLE_DESC, conn->apd); + CheckError(status, "SQLFreeHandle(SQL_HANDLE_DESC)", conn); + conn->apd = nullptr; EXPECT_EQ(Disconnect(conn), SQL_SUCCESS); //////////////// /// USE ANSI @@ -852,6 +855,9 @@ TEST(StatementTest, SQLExecute_UsingDescriptor) { CheckError(status, "SQLAllocHandle", conn); EXPECT_EQ(InsertStatementWithoutBindParameter(conn, true), SQL_SUCCESS); + status = SQLFreeHandle(SQL_HANDLE_DESC, conn->apd); + CheckError(status, "SQLFreeHandle(SQL_HANDLE_DESC)", conn); + conn->apd = nullptr; EXPECT_EQ(Disconnect(conn), SQL_SUCCESS); } diff --git a/vcpkg.json b/vcpkg.json index 6122c1ecbc..dba31fd8fa 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -30,6 +30,7 @@ }, { "name": "grpc", "version>=": "1.68.2" }, { "name": "opentelemetry-cpp", "version>=": "1.18.0" }, + { "name": "protobuf", "version>=": "5.29.2" }, "nlohmann-json", "benchmark", { "name": "gtest", "version>=": "1.15.2" }