Skip to content

Commit 8e98720

Browse files
committed
generate a fuzzing corpus by extracting code from testrunner
1 parent d901661 commit 8e98720

2 files changed

Lines changed: 76 additions & 0 deletions

File tree

.github/workflows/corpus.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Syntax reference https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions
2+
# Environment reference https://help.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners
3+
name: corpus
4+
5+
on:
6+
schedule:
7+
- cron: '0 0 * * 0'
8+
workflow_dispatch:
9+
10+
permissions:
11+
contents: read
12+
13+
jobs:
14+
corpus:
15+
runs-on: ubuntu-22.04
16+
if: ${{ github.repository_owner == 'cppcheck-opensource' }}
17+
18+
steps:
19+
- uses: actions/checkout@v4
20+
with:
21+
persist-credentials: false
22+
23+
- name: ccache
24+
uses: hendrikmuhs/ccache-action@v1.2
25+
with:
26+
key: ${{ github.workflow }}-${{ runner.os }}
27+
28+
- name: Install missing software on ubuntu
29+
run: |
30+
sudo apt-get update
31+
sudo apt-get install -y fdupes
32+
33+
- name: build testrunner
34+
run: |
35+
store_dir=$(pwd)/store
36+
mkdir $store_dir
37+
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
38+
make -j$(nproc) CXXOPTS="-Werror" CPPOPTS="-DSTORE_INPUT_DIR=\"\\\"$store_dir\\\"\"" testrunner
39+
40+
- name: run testrunner
41+
run: |
42+
./testrunner -q
43+
44+
- name: de-duplicate files
45+
run: |
46+
set -x
47+
ls -l ./store | wc -l
48+
echo "removing duplicates"
49+
fdupes -qdN ./store > /dev/null
50+
ls -l ./store | wc -l
51+
# print largest size
52+
ls -l ./store | cut -d' ' -f5 | sort -u -n -r | head -n1
53+
54+
- uses: actions/upload-artifact@v4
55+
if: success()
56+
with:
57+
name: corpus
58+
path: ./store

lib/tokenlist.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,26 @@ bool TokenList::createTokensFromBuffer(const char* data, size_t size)
333333

334334
//---------------------------------------------------------------------------
335335

336+
#ifdef STORE_INPUT_DIR
337+
#include <atomic>
338+
#include <fstream>
339+
340+
static void storeInput(const char* data, size_t size)
341+
{
342+
static std::atomic_uint64_t num(0);
343+
{
344+
std::ofstream out(STORE_INPUT_DIR "/" + std::to_string(num++));
345+
out.write(data, size);
346+
}
347+
}
348+
#endif
349+
336350
bool TokenList::createTokensFromBufferInternal(const char* data, size_t size, const std::string& file0)
337351
{
352+
#ifdef STORE_INPUT_DIR
353+
storeInput(data, size);
354+
#endif
355+
338356
simplecpp::OutputList outputList;
339357
simplecpp::TokenList tokens({data, size}, mFiles, file0, &outputList);
340358

0 commit comments

Comments
 (0)