Skip to content

Commit

Permalink
add CodeQL code scanning and fix several identified issues (#354)
Browse files Browse the repository at this point in the history
* initial CodeQL workflow file

* fix several CodeQL issues

* fix another CodeQL issue

* disable automatic creation of SPIR-V files for now

* more attempts to validate that the home directory is a valid directory

* add a call to realpath to validate that the home directory is valid

* cleanup
  • Loading branch information
bashbaug committed Apr 17, 2024
1 parent edfb3ef commit 9ccb72e
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 102 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: analyze

permissions:
contents: read

on:
push:
paths-ignore:
- '**/*.md'
pull_request:
paths-ignore:
- '**/*.md'
branches:
- main

env:
BUILD_TYPE: RelWithDebInfo

jobs:
analyze:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]

runs-on: ${{matrix.os}}

permissions:
security-events: write

steps:
- uses: actions/checkout@v4

- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: cpp

- name: Create Build Directory
run: cmake -E make_directory ${{runner.workspace}}/build

- name: Run CMake
shell: bash
working-directory: ${{runner.workspace}}/build
run: cmake -DENABLE_CLILOADER=1 -DCMAKE_BUILD_TYPE=$BUILD_TYPE $GITHUB_WORKSPACE

- name: Build
working-directory: ${{runner.workspace}}/build
shell: bash
run: cmake --build . --parallel 4 --config $BUILD_TYPE

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
22 changes: 9 additions & 13 deletions intercept/OS/OS_linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,21 +202,17 @@ inline bool Services::CheckMDAPIPermissions(
const char* path = "/proc/sys/dev/i915/perf_stream_paranoid";
bool available = false;

struct stat sb;
if( stat(path, &sb) == 0 )
uint64_t value = 1;
int fd = open(path, 0);
if( fd > 0 )
{
uint64_t value = 1;
int fd = open(path, 0);
if( fd > 0 )
char buf[32];
int n = read(fd, buf, sizeof(buf) - 1);
close(fd);
if( n > 0 )
{
char buf[32];
int n = read(fd, buf, sizeof(buf) - 1);
close(fd);
if( n > 0 )
{
buf[n] = 0;
value = strtoull(buf, NULL, 0);
}
buf[n] = 0;
value = strtoull(buf, NULL, 0);
}

if( value == 0 || geteuid() == 0 )
Expand Down
57 changes: 17 additions & 40 deletions intercept/OS/OS_linux_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,6 @@ class Services_Common
void GetDumpDirectoryNameWithoutPid(
const std::string& subDir,
std::string& directoryName ) const;
void GetDumpDirectoryNameWithoutProcessName(
const std::string& subDir,
std::string& directoryName) const;
void MakeDumpDirectories(
const std::string& fileName ) const;

Expand Down Expand Up @@ -218,32 +215,34 @@ inline void Services_Common::GetDumpDirectoryNameWithoutPid(
const std::string& subDir,
std::string& directoryName ) const
{
// Get the home directory and add our directory name.
if( LOG_DIR )
{
// Return log dir override if set in regkeys
directoryName = LOG_DIR;
}
else
{
// Get the home directory and add our directory name.
const char *envVal = getenv("HOME");
char* resolved_path = realpath(envVal, nullptr);
if( resolved_path )
{
directoryName = resolved_path;
free(resolved_path);
resolved_path = nullptr;
}
else
{
#ifndef __ANDROID__
directoryName = getenv("HOME");
#ifdef __ANDROID__
directoryName = "/sdcard/Intel";
#else
const char *envVal = getenv("HOME");
if( envVal == NULL )
{
directoryName = "/sdcard/Intel";
}
else
{
directoryName = envVal;
}
directoryName = "/tmp/Intel";
#endif
directoryName += "/";
directoryName += subDir;
directoryName += "/";
}
directoryName += "/";
directoryName += subDir;
directoryName += "/";

// Add the process name to the directory name.
directoryName += GetProcessName();
}
Expand All @@ -265,28 +264,6 @@ inline void Services_Common::GetDumpDirectoryName(
}
}

inline void Services_Common::GetDumpDirectoryNameWithoutProcessName(
const std::string& subDir,
std::string& directoryName) const
{
// Get the home directory and add our directory name.
if( LOG_DIR )
{
// Return log dir override if set in regkeys
directoryName = LOG_DIR;
}
else
{
directoryName = getenv("HOME");
directoryName += "/";
directoryName += subDir;
directoryName += "/";
}
#ifdef __ANDROID__
__android_log_print(ANDROID_LOG_INFO, "clIntercept", "dumpDir=%s\n", directoryName.c_str());
#endif
}

inline void Services_Common::MakeDumpDirectories(
const std::string& fileName ) const
{
Expand Down
16 changes: 0 additions & 16 deletions intercept/OS/OS_mac_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,6 @@ class Services_Common
void GetDumpDirectoryNameWithoutPid(
const std::string& subDir,
std::string& directoryName ) const;
void GetDumpDirectoryNameWithoutProcessName(
const std::string& subDir,
std::string& directoryName) const;
void MakeDumpDirectories(
const std::string& fileName ) const;

Expand Down Expand Up @@ -213,19 +210,6 @@ inline void Services_Common::GetDumpDirectoryName(
}
}

inline void Services_Common::GetDumpDirectoryNameWithoutProcessName(
const std::string& subDir,
std::string& directoryName) const
{
// Get the home directory and add our directory name.
{
directoryName = getenv("HOME");
directoryName += "/";
directoryName += subDir;
directoryName += "/";
}
}

inline void Services_Common::MakeDumpDirectories(
const std::string& fileName ) const
{
Expand Down
30 changes: 0 additions & 30 deletions intercept/OS/OS_windows_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,6 @@ class Services_Common
void GetDumpDirectoryNameWithoutPid(
const std::string& subDir,
std::string& directoryName ) const;
void GetDumpDirectoryNameWithoutProcessName(
const std::string& subDir,
std::string& directoryName) const;
void MakeDumpDirectories(
const std::string& fileName ) const;

Expand Down Expand Up @@ -288,33 +285,6 @@ inline void Services_Common::GetDumpDirectoryName(
}
}

inline void Services_Common::GetDumpDirectoryNameWithoutProcessName(
const std::string& subDir,
std::string& directoryName) const
{
// Return log dir override if set in regkeys
if( LOG_DIR )
{
directoryName = LOG_DIR;
return;
}

// Get the system root and add our directory name.
{
char* systemDrive = NULL;
size_t length = 0;

_dupenv_s(&systemDrive, &length, "SystemDrive");

directoryName = systemDrive;
directoryName += "/Intel/";
directoryName += subDir;
directoryName += "/";

free(systemDrive);
}
}

inline void Services_Common::MakeDumpDirectories(
const std::string& fileName ) const
{
Expand Down
4 changes: 2 additions & 2 deletions intercept/mdapi/MetricsDiscoveryHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,13 +446,13 @@ uint32_t MDHelper::GetMetricsFromReports(
const uint32_t metricsCount = m_MetricSet->GetParams()->MetricsCount;
const uint32_t informationCount = m_MetricSet->GetParams()->InformationCount;

results.resize( ( metricsCount + informationCount ) * numReports );
results.resize( ( metricsCount + informationCount ) * (size_t)numReports );

TCompletionCode res = MetricsDiscovery::CC_ERROR_GENERAL;
uint32_t outReportCount = 0;
if( m_IncludeMaxValues )
{
maxValues.resize( metricsCount * numReports );
maxValues.resize( metricsCount * (size_t)numReports );
res = ((MetricsDiscovery::IMetricSet_1_5*)m_MetricSet)->CalculateMetrics(
(const unsigned char*)pReportData,
reportSize,
Expand Down
3 changes: 2 additions & 1 deletion intercept/src/dispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11122,7 +11122,8 @@ CL_API_ENTRY cl_int CL_API_CALL clCommandSVMMemcpyKHR(
command_queue,
dst_ptr,
src_ptr,
size );
size,
syncPointWaitList.c_str() );
HOST_PERFORMANCE_TIMING_START();

cl_int retVal = dispatchX.clCommandSVMMemcpyKHR(
Expand Down

0 comments on commit 9ccb72e

Please sign in to comment.