-
Notifications
You must be signed in to change notification settings - Fork 322
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
65 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
|
||
using System; | ||
|
||
namespace Microsoft.KernelMemory.Diagnostics; | ||
|
||
public static class CodeQL | ||
{ | ||
/// <summary> | ||
/// See https://codeql.github.com/codeql-query-help/csharp/cs-log-forging/ | ||
/// </summary> | ||
public static string? NLF(this string? text) | ||
{ | ||
if (text == null) { return text; } | ||
|
||
return text | ||
.Replace("\n", "[char(10)]", StringComparison.Ordinal) | ||
.Replace("\r", "[char(13)]", StringComparison.Ordinal); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && cd ../.. && pwd)" | ||
CODEQL_DB=${REPO_DIR}/.codeql/db | ||
CODEQL_REPORT=${REPO_DIR}/.codeql/results.sarif | ||
|
||
cd $REPO_DIR | ||
|
||
echo -e "\033[1;32m- Repository:\033[0m ${REPO_DIR}" | ||
echo -e "\033[1;32m- Report :\033[0m ${CODEQL_REPORT}.sarif\n" | ||
read -p "Press Enter to DELETE the existing CodeQL results and RUN A NEW analysis." | ||
|
||
mkdir -p ${REPO_DIR}/.codeql | ||
rm -f ${CODEQL_REPORT} | ||
|
||
echo -e "\033[1;32m\n### Install CodeQL C# queries ###\033[0m" | ||
codeql pack download "codeql/csharp-queries" | ||
|
||
echo -e "\033[1;32m\n### Perform CodeQL Analysis ###\033[0m" | ||
rm -fR ${CODEQL_DB} | ||
codeql database create ${CODEQL_DB} --source-root=${REPO_DIR} --language=csharp --build-mode=autobuild | ||
codeql database print-baseline ${CODEQL_DB} | ||
|
||
echo -e "\033[1;32m\n### Export CodeQL results ###\033[0m" | ||
codeql database analyze ${CODEQL_DB} --format=sarif-latest --output=${CODEQL_REPORT} | ||
|
||
echo -e "\033[1;32m\n### Done ###\033[0m" | ||
echo -e "\033[1;32m- Report:\033[0m ${CODEQL_REPORT}" |