Skip to content
Snippets Groups Projects
Commit 263fadcc authored by Henrik Mathias Berg's avatar Henrik Mathias Berg
Browse files

:D

parents
No related branches found
No related tags found
No related merge requests found
IndentWidth: 2
AccessModifierOffset: -2
UseTab: Never
ColumnLimit: 0
MaxEmptyLinesToKeep: 2
NamespaceIndentation: All
build
crash-*
{
"files.associations": {
"cstdlib": "cpp",
"*.tcc": "cpp",
"memory": "cpp",
"new": "cpp"
}
}
\ No newline at end of file
cmake_minimum_required(VERSION 2.8)
project(fuzzing-example)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11 -Wall -Wextra")
add_library(utility INTERFACE)
target_include_directories(utility INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
add_executable(main main.c)
target_link_libraries(main utility)
enable_testing()
add_subdirectory(tests)
LICENSE 0 → 100644
MIT License
Copyright (c) 2019-2020 ntnu-tdat3020
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
# Fuzzing example
## Prerequisites
* Linux (preferably Arch Linux or an Arch Linux based distribution such as Manjaro) or MacOS
* [juCi++](https://gitlab.com/cppit/jucipp)
## Instructions using juCi++
1. Clone this repository
2. Run juCi++ with the following arguments from a terminal:
* Linux: `CC=clang juci fuzzing-example`
* MacOS: `CC=/usr/local/opt/llvm/bin/clang juci fuzzing-example`
3. Open `tests/utility_fuzzer_test.c` and run using either:
* Compile and Run in the Project menu
* Start/Continue in the Debug menu
## Instructions using a terminal on Linux
```sh
git clone https://gitlab.com/ntnu-tdat3020/fuzzing-example
mkdir fuzzing-example/build
cd fuzzing-example/build
CC=clang cmake ..
make
./tests/utility_fuzzer_test -max_total_time=60 # Cancel fuzzing after 60 seconds
```
main.c 0 → 100644
#include "utility.h"
#include <stdio.h>
#include <string.h>
const char *replaceString(const char *line, size_t len);
int main() {
const char *test = "hei&der<borte>!";
size_t size = strlen(test);
const char *res = replaceString(test, size);
printf("%s\n", res);
free(res);
return 0;
}
add_executable(utility_test utility_test.c)
target_link_libraries(utility_test utility)
target_compile_options(utility_test PRIVATE -fsanitize=address)
target_link_options(utility_test PRIVATE -fsanitize=address)
add_test(NAME utility_test COMMAND utility_test)
add_executable(utility_fuzzer_test utility_fuzzer_test.c)
target_link_libraries(utility_fuzzer_test utility)
target_compile_options(utility_fuzzer_test PRIVATE -fsanitize=address,fuzzer)
target_link_options(utility_fuzzer_test PRIVATE -fsanitize=address,fuzzer)
add_test(NAME utility_fuzzer_test COMMAND utility_fuzzer_test)
#include "../utility.h"
#include <stddef.h>
#include <stdint.h>
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
const char *test = replaceString((const char *)data, size);
free(test);
return 0;
}
#include "../utility.h"
#include <assert.h>
#include <string.h>
int main() {
char *stringInput = "1 < 2 && 2 > 1";
char *stringResult = "1 &lt; 2 &amp;&amp; 2 &gt; 1";
char *actualResult = replaceString(stringInput, strlen(stringInput));
assert(actualResult == stringResult);
free(actualResult);
}
#pragma once
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
const char *replaceString(const char *str, size_t len) {
char amp[5] = "&amp;";
char lt[4] = "&lt;";
char gt[4] = "&gt;";
char *res;
res = malloc(len * 5 + 1);
// printf("%s\n", strlen(res));
int k = 0;
for (size_t i = 0; i < len;) {
if (str[i] == '&') {
for (int j = 0; j < 5; j++, k++) {
res[k] = amp[j];
}
i++;
} else if (str[i] == '<') {
for (int j = 0; j < 4; j++, k++) {
res[k] = lt[j];
}
i++;
} else if (str[i] == '>') {
for (int j = 0; j < 4; j++, k++) {
res[k] = gt[j];
}
i++;
} else {
res[k] = str[i];
k++;
i++;
}
}
res = realloc(res, k);
return res;
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment