• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash -eu
2# Copyright 2019 Google Inc.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#      http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16################################################################################
17
18PROJECT=osquery
19
20# Ensure xlocale.h is found.
21ln -s /usr/include/locale.h /usr/include/xlocale.h
22
23# Move the project content into the current overlay.
24# CMake builtin 'rename' will attempt a hardlink.
25( cd / &&\
26  mv "${SRC}/${PROJECT}" "${SRC}/${PROJECT}-dev" &&\
27  mv "${SRC}/${PROJECT}-dev" "${SRC}/${PROJECT}" )
28
29pushd "${SRC}/${PROJECT}"
30
31mkdir build && pushd build
32
33cmake \
34  -DOSQUERY_VERSION:string=0.0.0-fuzz \
35  -DOSQUERY_ENABLE_ADDRESS_SANITIZER:BOOL=ON \
36  -DOSQUERY_BUILD_FUZZERS:BOOL=ON \
37  -DOSQUERY_IGNORE_CMAKE_MAX_VERSION_CHECK:BOOL=ON \
38  -DOSQUERY_BUILD_AWS:BOOL=OFF \
39  ..
40
41cmake \
42  "-DCMAKE_EXE_LINKER_FLAGS=${LIB_FUZZING_ENGINE} -Wl,-rpath,'\$ORIGIN/lib'" \
43  ..
44
45# Fix circular definitions
46# See: https://github.com/osquery/osquery/issues/6551
47sed -i 's/AUDIT_FILTER_EXCLUDE/AUDIT_FILTER_EXCLUDE1/g' /src/osquery/libraries/cmake/source/libaudit/src/lib/libaudit.h
48
49# Build harnesses
50cmake --build . -j$(nproc) --target osqueryfuzz-config
51cmake --build . -j$(nproc) --target osqueryfuzz-sqlquery
52
53# Cleanup
54find . -type f -name '*.o' -delete
55rm -rf "${SRC}/${PROJECT}/libraries/cmake/source/libudev/src/test"
56rm -rf libs/src/patched-source/libudev/src/test
57
58# Move libunwind to output path
59mkdir -p "${OUT}/lib"
60cp /usr/lib/x86_64-linux-gnu/libunwind.so.8 "${OUT}/lib"
61
62# Move harnesses to output path
63cp osquery/main/harnesses/osqueryfuzz-config "${OUT}/osqueryfuzz-config"
64cp osquery/main/harnesses/osqueryfuzz-sqlquery "${OUT}/osqueryfuzz-sqlquery"
65
66# Build supporting files
67popd
68tools/harnesses/osqueryfuzz_config_corpus.sh "${OUT}/osqueryfuzz-config_seed_corpus.zip"
69tools/harnesses/osqueryfuzz_config_dict.sh "${OUT}/osqueryfuzz-config.dict"
70tools/harnesses/osqueryfuzz_sqlquery_corpus.sh "${OUT}/osqueryfuzz-sqlquery_seed_corpus.zip"
71cp tools/harnesses/osqueryfuzz_sqlquery.dict "${OUT}/osqueryfuzz-sqlquery.dict"
72