Skip to content

Commit becab0f

Browse files
Anshu6250sachinpro
authored andcommitted
fix: asan git check
1 parent fdaf57e commit becab0f

9 files changed

Lines changed: 70 additions & 27 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ if (ENABLE_SANITIZER)
5151
"${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
5252
set(CMAKE_SHARED_LINKER_FLAGS
5353
"${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=address")
54+
add_compile_definitions(ODBC_ADDRESS_SANITIZER)
5455
else ()
5556
message(WARNING "AddressSanitizer is only supported on UNIX platforms")
5657
endif ()

ci/cloudbuild/builds/integration-bq-driver-asan.sh

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ git checkout "$VCPKG_VERSION"
4242
./bootstrap-vcpkg.sh -disableMetrics
4343

4444
cd "$WORKSPACE_DIR"
45+
4546
# This runs all the unit tests
4647
mapfile -t args < <(bazel::common_args)
4748
mapfile -t unit_tests_args < <(unit_tests::bazel_args)
@@ -55,8 +56,9 @@ mapfile -t cmake_args < <(cmake::common_args)
5556
BUILD_DIR="/opt/odbc-driver"
5657
# This is the name of DSN set in odbc.ini
5758
export ODBC_TESTS_DSN="SampleDSNGoogleDriver"
58-
export ASAN_OPTIONS="detect_container_overflow=0:detect_leaks=1"
59-
export LSAN_OPTIONS="use_tls=0:suppressions=/opt/odbc-driver/lsan.supp:print_suppressions=0"
59+
export LSAN_OPTIONS="use_tls=0:suppressions=/opt/odbc-driver/lsan.supp:print_suppressions=0:fast_unwind_on_malloc=0"
60+
ASAN_SYMBOLIZER_PATH="$(command -v llvm-symbolizer)"
61+
export ASAN_SYMBOLIZER_PATH
6062

6163
export CPP_BIGQUERY_ODBC_TEST_TABLE_PREFIX=${TRIGGER_NAME//[-:;.,?]/_}_${BRANCH_NAME//[-:;.,?]/_}
6264

@@ -76,6 +78,8 @@ fi
7678
io::run cmake -B "$BUILD_DIR" \
7779
"${cmake_args[@]}" \
7880
-DCMAKE_TOOLCHAIN_FILE="${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" \
81+
-DVCPKG_OVERLAY_TRIPLETS="${WORKSPACE_DIR}/ci/cloudbuild/triplets" \
82+
-DVCPKG_TARGET_TRIPLET=x64-linux-asan \
7983
-DCMAKE_CXX_STANDARD=17 \
8084
-DODBC_INTEGRATION_TESTING=ON \
8185
-DBQ_DRIVER_INTEGRATION_TESTS=ON \
@@ -87,6 +91,6 @@ io::run cmake -B "$BUILD_DIR" \
8791
io::run cmake --build cmake-out
8892

8993
# Copy the roots.pem file to the .so directory to run test cases.
90-
cp /opt/odbc-driver/roots.pem "cmake-out/google/cloud/odbc/roots.pem"
94+
io::run cp /opt/odbc-driver/roots.pem "cmake-out/google/cloud/odbc/roots.pem"
9195
mapfile -t ctest_args < <(ctest::common_args)
9296
io::run env -C cmake-out ctest "${ctest_args[@]}"

ci/cloudbuild/dockerfiles/ubuntu-22.04-install.Dockerfile

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ RUN apt-get update && \
2222
build-essential \
2323
# Dependency for arrow
2424
bison \
25-
clang \
25+
clang-12 \
26+
lld-12 \
2627
cmake \
2728
curl \
2829
# Dependency for arrow
@@ -31,8 +32,10 @@ RUN apt-get update && \
3132
git \
3233
gcc \
3334
g++ \
34-
libc++-dev \
35-
libc++abi-dev \
35+
# Required by Ubsan in Ubuntu 22.04
36+
libunwind-12-dev \
37+
libc++-12-dev \
38+
libc++abi-12-dev \
3639
libcurl4-openssl-dev \
3740
# Needed to use autoreconf
3841
libltdl-dev \
@@ -58,22 +61,28 @@ RUN apt-get update && \
5861
apt-utils \
5962
ca-certificates \
6063
apt-transport-https \
61-
clang-tidy
62-
63-
# Set Clang 12 as default
64-
RUN update-alternatives --install /usr/bin/cc cc /usr/bin/clang 100 && \
65-
update-alternatives --install /usr/bin/c++ c++ /usr/bin/clang++ 100
66-
67-
# Set the compiler environment variables
68-
ENV CC=/usr/bin/clang
69-
ENV CXX=/usr/bin/clang++
64+
clang-tidy-12
7065

7166
# Needed for the existing driver v3.1.2.1004+
7267
RUN locale-gen en_US.UTF-8
7368
ENV LANG en_US.UTF-8
7469
ENV LANGUAGE en_US.UTF-8
7570
ENV LC_ALL en_US.UTF-8
7671

72+
# Set clang as default
73+
RUN update-alternatives --install /usr/bin/clang clang /usr/bin/clang-12 100 && \
74+
update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-12 100
75+
76+
ENV CC=clang
77+
ENV CXX=clang++
78+
79+
# Install modern CMake locally
80+
RUN mkdir -p /opt/cmake && \
81+
curl -fsSL https://github.com/Kitware/CMake/releases/download/v3.30.1/cmake-3.30.1-linux-x86_64.tar.gz \
82+
| tar -xz --strip-components=1 -C /opt/cmake
83+
84+
ENV PATH=/opt/cmake/bin:$PATH
85+
7786
# clang-tidy-cache needs python
7887
RUN update-alternatives --install /usr/bin/python python $(which python3) 10
7988

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright 2026 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
4+
# use this file except in compliance with the License. You may obtain a copy of
5+
# the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
# License for the specific language governing permissions and limitations under
13+
# the License.
14+
15+
# Keep ASan-instrumented dependencies separate from the normal x64-linux
16+
# binaries in vcpkg's binary cache.
17+
set(VCPKG_TARGET_ARCHITECTURE x64)
18+
set(VCPKG_CMAKE_SYSTEM_NAME Linux)
19+
set(VCPKG_CRT_LINKAGE dynamic)
20+
set(VCPKG_LIBRARY_LINKAGE static)
21+
set(VCPKG_C_FLAGS "-O1 -fsanitize=address -fno-omit-frame-pointer -g")
22+
set(VCPKG_CXX_FLAGS "-O1 -fsanitize=address -fno-omit-frame-pointer -g")
23+
set(VCPKG_LINKER_FLAGS "-fsanitize=address")

ci/gha/builds/lib/lsan.supp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@ leak:conv_text_m2d
22
leak:__interceptor_malloc
33
leak:__interceptor_calloc
44
leak:_iodbcdm_driverload
5+
leak:_iodbcdm_driverunload
6+
leak:_iodbcdm_pushsqlerr
7+
leak:grpc_jwt_encode_and_sign
8+
leak:grpc_core::DoSslRead
9+
leak:grpc_core::DoSslWrite
510
leak:calloc
611
leak:Diagnostics::AddStatusRecord
712
leak:StatusRecord
813
leak:std::__cxx11::basic_string
914
leak:_iodbcdm_SetConnectOption_init
10-
leak:ld-linux-x86-64.so.2
11-
leak:_dl_exception_create_format
12-
leak:libc.so.6
13-
leak:CRYPTO_zalloc
14-
leak:grpc_jwt_encode_and_sign
15-
leak:_iodbcdm_pushsqlerr

google/cloud/odbc/integration_tests/odbc_driver_tests/connection_test.cc

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,13 +1279,7 @@ TEST(ConnectionTest, SQLBrowseConnect_InvalidConnectionAttribute) {
12791279
HasSubstr("Catalog:Catalog=?;OAuthMechanism:OAuthMechanism=?"));
12801280
#endif // _WIN32
12811281
}
1282-
// Pass `false` to indicate that the Driver Manager (DM) will automatically
1283-
// free the environment handle when the last connection handle is released.
1284-
#ifdef _WIN32
1285-
CleanupODBCHandles(*conn, false);
1286-
#else
12871282
CleanupODBCHandles(*conn);
1288-
#endif
12891283
}
12901284

12911285
TEST(ConnectionTest, SQLBrowseConnect_InvalidConnectionString) {
@@ -1545,6 +1539,9 @@ TEST(SQLDisconnect, CheckAllHandlesAreFreed) {
15451539
auto status = SQLAllocHandle(SQL_HANDLE_DESC, conn->hdbc, &conn->ard);
15461540
CheckError(status, "SQLAllocHandle(SQL_HANDLE_DESC)", conn);
15471541

1542+
status = SQLFreeHandle(SQL_HANDLE_DESC, conn->ard);
1543+
CheckError(status, "SQLFreeHandle(SQL_HANDLE_DESC)", conn);
1544+
15481545
status = SQLDisconnect(conn->hdbc);
15491546
CheckError(status, "SQLDisconnect", conn);
15501547

google/cloud/odbc/integration_tests/odbc_driver_tests/driver_properties_test.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,9 @@ TEST(SQLGetTypeInfoTest, all_datatypes) {
271271
// reach this TEST
272272
// TODO(b/477506552): Fix memory issue in SQLGetTypeInfoTest bind offset
273273
TEST(SQLGetTypeInfoTest, all_datatypes_with_offset) {
274+
#ifdef ODBC_ADDRESS_SANITIZER
275+
GTEST_SKIP() << "The row-bind-offset test is not ASAN-safe.";
276+
#endif
274277
#ifdef NDEBUG
275278
GTEST_SKIP();
276279
#endif // NDEBUG

google/cloud/odbc/integration_tests/odbc_driver_tests/statement_test.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,9 @@ TEST(StatementTest, SQLExecute_UsingDescriptor) {
840840
CheckError(status, "SQLAllocHandle", conn);
841841

842842
EXPECT_EQ(InsertStatementWithoutBindParameter(conn), SQL_SUCCESS);
843+
status = SQLFreeHandle(SQL_HANDLE_DESC, conn->apd);
844+
CheckError(status, "SQLFreeHandle(SQL_HANDLE_DESC)", conn);
845+
conn->apd = nullptr;
843846
EXPECT_EQ(Disconnect(conn), SQL_SUCCESS);
844847
////////////////
845848
/// USE ANSI
@@ -862,6 +865,9 @@ TEST(StatementTest, SQLExecute_UsingDescriptor) {
862865
CheckError(status, "SQLAllocHandle", conn);
863866

864867
EXPECT_EQ(InsertStatementWithoutBindParameter(conn, true), SQL_SUCCESS);
868+
status = SQLFreeHandle(SQL_HANDLE_DESC, conn->apd);
869+
CheckError(status, "SQLFreeHandle(SQL_HANDLE_DESC)", conn);
870+
conn->apd = nullptr;
865871
EXPECT_EQ(Disconnect(conn), SQL_SUCCESS);
866872
}
867873

vcpkg.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
},
3131
{ "name": "grpc", "version>=": "1.68.2" },
3232
{ "name": "opentelemetry-cpp", "version>=": "1.18.0" },
33+
{ "name": "protobuf", "version>=": "5.29.2" },
3334
"nlohmann-json",
3435
"benchmark",
3536
{ "name": "gtest", "version>=": "1.15.2" }

0 commit comments

Comments
 (0)