Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added security vulnerabilities for sonarqube analysis #3

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
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
27 changes: 26 additions & 1 deletion main.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,38 @@
#include <iostream>
#include <cstring>
#include "functions.h"
#include <random>
#include <string.h>
#include <stdio.h>

int generateRandomId()
{
int random_int = std::rand(); // Should use functions which rely on a strong random number generator, not a pseudo-random number generator becasuse it can be predicted
return random_int;
}

void bufferOverflow(char * input){
char buffer[20];
strcpy(buffer, input); // Noncompliant; `input` length is not checked and it may overflow `buffer`
}

int main()
{
int values[5] = {1,2,3,4,5};
double avg = getAverage(values, 10);
char array[10];
void *pos = memchr(array, '@', 42);
std::cout << avg;
std::cout << avg << std::endl;

// Random Id issue
int id = generateRandomId();
std::cout << "Random'ish id = " << id << std::endl;

// Hardcoded IP issue
char host[10];
strcpy(host, "10.10.0.1"); // Sensitive
std::cout << "Hardcoded Server IP = " << id << std::endl;

return 0;
}

Loading