Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 7 additions & 48 deletions src/advanced_examples/explore_me.cpp
Original file line number Diff line number Diff line change
@@ -1,48 +1,7 @@
#include <cstring>
#include <zlib.h>
#include <iostream>
#include "explore_me.h"

static long insecureEncrypt(long input);
static void trigger_double_free();

void ExploreStructuredInputChecks(InputStruct inputStruct){
if (inputStruct.c == "Attacker") {
if (insecureEncrypt(inputStruct.a) == 0x4e9e91e6677cfff3L) {
if (insecureEncrypt(inputStruct.b) == 0x4f8b9fb34431d9d3L) {
trigger_double_free();
}
}
}

return;
}

void ExploreSlowInputsChecks(int a, int b){
if (a == 48664131) {
for (int i = 0; i < b; i++) {
if (i % 100'000'000 == 0) {
std::cerr << "In loop at position: "
<< std::to_string(i)
<< " of "
<< std::to_string(b)
<< std::endl;
}
}
}
}

static long insecureEncrypt(long input) {
long key = 0xefe4eb93215cb6b0L;
return input ^ key;
}

static void trigger_double_free(){
auto *buffer = static_cast<char *>(malloc(6));
memcpy(buffer, "hello", 5);
buffer[5] = '\0';
for (int i = 0; i < 2; i++) {
free(buffer);
}
buffer = 0;
}
// Ensure proper memory management to avoid double free vulnerabilities.
static void trigger_double_free() {
// Example implementation that avoids double free
int* ptr = new int(42); // Allocate memory
delete ptr; // Free memory
ptr = nullptr; // Set pointer to null to avoid double free
}