Skip to content
Snippets Groups Projects
Commit 7caf87c5 authored by Nawaf2.Alanazi@live.uwe.ac.uk's avatar Nawaf2.Alanazi@live.uwe.ac.uk
Browse files

Initial commit - SecureCoding project

parents
No related branches found
No related tags found
No related merge requests found
#include <iostream>
#include <cstring>
void bufferOverflow() {
char buffer[10];
std::cout << "Enter input: ";
std::cin >> buffer;
std::cout << "You entered: " << buffer << std::endl;
}
int main() {
bufferOverflow();
return 0;
}
\ No newline at end of file
File added
#include <iostream>
#include <cstdio>
void formatStringVuln() {
char userInput[50];
std::cout << "Enter string: ";
std::cin >> userInput;
printf(userInput);
}
int main() {
formatStringVuln();
return 0;
}
\ No newline at end of file
File added
#include <iostream>
void integerOverflow() {
unsigned int max = 4294967295;
std::cout << "Max: " << max << "\nAfter overflow: " << (max + 1) << std::endl;
}
int main() {
integerOverflow();
return 0;
}
\ No newline at end of file
File added
#include <iostream>
#include <thread>
int sharedResource = 0;
void raceCondition() {
auto increment = []() { for (int i = 0; i < 1000; ++i) sharedResource++; };
std::thread t1(increment), t2(increment);
t1.join(); t2.join();
std::cout << "Shared Resource: " << sharedResource << std::endl;
}
int main() {
raceCondition();
return 0;
}
\ No newline at end of file
File added
#include <iostream>
void useAfterFree() {
int* ptr = new int(42);
delete ptr;
std::cout << "Dangling pointer access: " << *ptr << std::endl;
}
int main() {
useAfterFree();
return 0;
}
\ No newline at end of file
File added
#include <iostream>
#include <string>
bool validateFilePath(const std::string& path) {
if (path.find("..") != std::string::npos) {
std::cerr << "Potential directory traversal attack!" << std::endl;
return false;
}
return true;
}
int main() {
std::string path;
std::cout << "Enter file path: ";
std::cin >> path;
validateFilePath(path);
return 0;
}
\ No newline at end of file
File added
#include <cstdlib>
#include <iostream>
void execExample() {
system("ls");
}
int main() {
execExample();
return 0;
}
\ No newline at end of file
File added
#include <cstdlib>
#include <iostream>
int main() {
std::cout << "Running system command..." << std::endl;
system("dir");
return 0;
}
\ No newline at end of file
File added
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