mirror of
https://github.com/valitydev/osquery-1.git
synced 2024-11-07 01:55:20 +00:00
Added make analyze (clang-analyze) and fixed output
This commit is contained in:
parent
38a757c7f0
commit
c4fb5d45ed
@ -26,7 +26,8 @@ endif()
|
||||
|
||||
project(OSQUERY)
|
||||
|
||||
if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
|
||||
if(DEFINED ENV{DEBUG})
|
||||
set(CMAKE_BUILD_TYPE "Debug")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -DDEBUG -O0")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -DDEBUG -O0")
|
||||
else()
|
||||
@ -34,6 +35,10 @@ else()
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2")
|
||||
endif()
|
||||
|
||||
if(DEFINED ENV{ANALYZE})
|
||||
set(CMAKE_CXX_COMPILER "${CMAKE_SOURCE_DIR}/tools/analysis/clang-analyze.sh")
|
||||
endif()
|
||||
|
||||
# Use osquery language to set platform/os
|
||||
execute_process(
|
||||
COMMAND "${CMAKE_SOURCE_DIR}/tools/provision.sh" get_platform
|
||||
|
10
Makefile
10
Makefile
@ -16,11 +16,15 @@ else
|
||||
endif
|
||||
|
||||
all: .setup
|
||||
cd build/$(BUILD_DIR) && cmake -DCMAKE_BUILD_TYPE= ../.. && \
|
||||
cd build/$(BUILD_DIR) && cmake ../.. && \
|
||||
$(MAKE) --no-print-directory $(MAKEFLAGS)
|
||||
|
||||
debug: .setup
|
||||
cd build/$(BUILD_DIR) && cmake -DCMAKE_BUILD_TYPE=Debug ../../ && \
|
||||
cd build/$(BUILD_DIR) && DEBUG=True cmake ../../ && \
|
||||
$(MAKE) --no-print-directory $(MAKEFLAGS)
|
||||
|
||||
analyze: .setup
|
||||
cd build/$(BUILD_DIR) && ANALYZE=True cmake ../../ && \
|
||||
$(MAKE) --no-print-directory $(MAKEFLAGS)
|
||||
|
||||
deps: .setup
|
||||
@ -40,7 +44,7 @@ endif
|
||||
|
||||
package:
|
||||
# Alias for packages (do not use CPack)
|
||||
cd build/$(BUILD_DIR) && cmake -DCMAKE_BUILD_TYPE= ../../ && \
|
||||
cd build/$(BUILD_DIR) && cmake ../../ && \
|
||||
$(MAKE) packages --no-print-directory $(MAKEFLAGS)
|
||||
|
||||
%::
|
||||
|
@ -62,7 +62,11 @@ void IOKitHIDEventPublisher::restart() {
|
||||
|
||||
// Enumerate initial set of devices matched before time=0.
|
||||
CFSetRef devices = IOHIDManagerCopyDevices(manager_);
|
||||
initial_device_count_ = devices == NULL ? 0 : CFSetGetCount(devices);
|
||||
if (devices == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
initial_device_count_ = CFSetGetCount(devices);
|
||||
CFRelease(devices);
|
||||
|
||||
// Register callbacks.
|
||||
|
@ -58,8 +58,7 @@ QueryData genGroups(QueryContext &context) {
|
||||
for (ODRecord *re in od_results) {
|
||||
Row r;
|
||||
r["groupname"] = std::string([[re recordName] UTF8String]);
|
||||
struct group *grp = nullptr;
|
||||
grp = getgrnam(r["groupname"].c_str());
|
||||
struct group *grp = getgrnam(r["groupname"].c_str());
|
||||
if (grp != nullptr) {
|
||||
r["gid"] = BIGINT(grp->gr_gid);
|
||||
r["gid_signed"] = BIGINT((int32_t) grp->gr_gid);
|
||||
|
@ -139,7 +139,6 @@ void genOpenDescriptors(int pid, descriptor_type type, QueryData &results) {
|
||||
|
||||
// Allocate structs for each descriptor.
|
||||
proc_fdinfo fds[bufsize / PROC_PIDLISTFD_SIZE];
|
||||
int num_fds = proc_pidinfo(pid, PROC_PIDLISTFDS, 0, fds, sizeof(fds));
|
||||
|
||||
for (auto fd_info : fds) {
|
||||
if (type == DESCRIPTORS_TYPE_VNODE &&
|
||||
|
@ -35,7 +35,7 @@ Status genQuarantineFile(const fs::path &path, QueryData &results) {
|
||||
return Status(1, "Failed to getxattr.");
|
||||
}
|
||||
|
||||
char *value = (char *)malloc(sizeof(char *) * bufferLength);
|
||||
char *value = (char *)malloc(sizeof(char) * bufferLength);
|
||||
getxattr(path.string().c_str(),
|
||||
kXattrQuarantine.c_str(),
|
||||
value,
|
||||
|
@ -52,6 +52,7 @@ QueryData genSMBIOSTables(QueryContext& context) {
|
||||
|
||||
if (smbios_data == nullptr || length == 0) {
|
||||
// Problem creating SMBIOS property.
|
||||
CFRelease(smbios);
|
||||
IOObjectRelease(service);
|
||||
return {};
|
||||
}
|
||||
|
@ -60,8 +60,7 @@ QueryData genUsers(QueryContext &context) {
|
||||
for (ODRecord *re in od_results) {
|
||||
Row r;
|
||||
r["username"] = std::string([[re recordName] UTF8String]);
|
||||
struct passwd *pwd = nullptr;
|
||||
pwd = getpwnam(r["username"].c_str());
|
||||
struct passwd *pwd = getpwnam(r["username"].c_str());
|
||||
if (pwd != nullptr) {
|
||||
r["uid"] = BIGINT(pwd->pw_uid);
|
||||
r["gid"] = BIGINT(pwd->pw_gid);
|
||||
|
42
tools/analysis/clang-analyze.sh
Executable file
42
tools/analysis/clang-analyze.sh
Executable file
@ -0,0 +1,42 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Copyright (c) 2014, Ruslan Baratov
|
||||
# All rights reserved.
|
||||
|
||||
declare -a BLACKLIST=(
|
||||
"osquery/devtools/shell.cpp"
|
||||
)
|
||||
|
||||
for BL_ITEM in ${BLACKLIST[@]}; do
|
||||
if [[ "$@" == *"${BL_ITEM}"* ]]; then
|
||||
clang++ "$@"
|
||||
exit 0;
|
||||
fi
|
||||
done
|
||||
|
||||
for x in "$@"; do
|
||||
if [ ! "${x}" == "-c" ]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
OUTPUT="`mktemp /tmp/clang-analyze.out.XXXXX`"
|
||||
BINARY="`mktemp /tmp/clang-analyze.bin.XXXXX`"
|
||||
|
||||
# analyze
|
||||
clang++ --analyze "$@" -o "${BINARY}" 2> "${OUTPUT}"
|
||||
|
||||
RESULT=0
|
||||
[ "$?" == 0 ] || RESULT=1
|
||||
[ -s "${OUTPUT}" ] && RESULT=1
|
||||
|
||||
cat "${OUTPUT}";
|
||||
rm -f "${OUTPUT}"
|
||||
rm -f "${BINARY}"
|
||||
|
||||
if [ "${RESULT}" == "1" ]; then
|
||||
exit 1;
|
||||
fi
|
||||
done
|
||||
|
||||
# compile real code
|
||||
clang++ "$@"
|
Loading…
Reference in New Issue
Block a user