Skip to content

Commit ced7b85

Browse files
author
Dae Glendowne
committed
Adding tutorials to repo
1 parent 6d25a22 commit ced7b85

24 files changed

Lines changed: 592 additions & 1 deletion

File tree

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
# Tutorials for CI Fuzz CLI
1+
# CI Fuzz CLI Tutorials
2+
3+
This repo contains tutorials to help you learn how to create your own fuzz tests with CI Fuzz CLI. Use these tutorials along with the following guides:
4+
5+
* [C++ Quick Start](https://docs.code-intelligence.com/cli-quick-start-cpp)
6+
* [Java Quick Start](https://docs.code-intelligence.com/cli-quick-start-java)

c_cpp/bazel/BUILD.bazel

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
load("@rules_cc//cc:defs.bzl", "cc_binary")
2+
3+
cc_binary(
4+
name = "main",
5+
srcs = ["main.cpp"],
6+
deps = ["//src:explore_me"],
7+
)

c_cpp/bazel/WORKSPACE

Whitespace-only changes.

c_cpp/bazel/main.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include "src/explore_me.h"
2+
3+
int main() {
4+
exploreMe(1, 1, "A");
5+
exploreMe(2147483647, 1, "A");
6+
exploreMe(2147483647, 2147483647, "A");
7+
exploreMe(2000000000, 2000000123, "A");
8+
exploreMe(2000000000, 2000000123, "FUZZ");
9+
}

c_cpp/bazel/src/BUILD.bazel

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
cc_library(
2+
name = "explore_me",
3+
srcs = ["explore_me.cpp"],
4+
hdrs = ["explore_me.h"],
5+
visibility = ["//visibility:public"],
6+
)
7+

c_cpp/bazel/src/explore_me.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include "explore_me.h"
2+
#include <cstdio>
3+
#include <cstring>
4+
using namespace std;
5+
6+
// just a function with multiple paths that can be discoverd by a fuzzer
7+
void exploreMe(int a, int b, string c) {
8+
if (a >= 20000) {
9+
if (b >= 2000000) {
10+
if (b - a < 100000) {
11+
if (c == "FUZZING") {
12+
// Trigger a heap buffer overflow
13+
char *s = (char *)malloc(1);
14+
strcpy(s, "too long");
15+
printf("%s\n", s);
16+
}
17+
}
18+
}
19+
}
20+
}

c_cpp/bazel/src/explore_me.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#include <string>
2+
using namespace std;
3+
4+
void exploreMe(int a, int b, string c);

c_cpp/bazel/test/BUILD.bazel

Whitespace-only changes.

c_cpp/cmake/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
cmake_minimum_required(VERSION 3.16)
2+
project(cmake_example)
3+
4+
set(CMAKE_CXX_STANDARD 11)
5+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
6+
7+
enable_testing()
8+
9+
add_subdirectory(src)
10+
11+
add_executable(${PROJECT_NAME} main.cpp )
12+
target_link_libraries(${PROJECT_NAME} PRIVATE exploreMe)

c_cpp/cmake/main.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include "src/explore_me.h"
2+
3+
int main() {
4+
exploreMe(1, 1, "A");
5+
exploreMe(2147483647, 1, "A");
6+
exploreMe(2147483647, 2147483647, "A");
7+
exploreMe(2000000000, 2000000123, "A");
8+
exploreMe(2000000000, 2000000123, "FUZZ");
9+
}

0 commit comments

Comments
 (0)