Skip to content

Instantly share code, notes, and snippets.

@0x09AL
Created June 30, 2020 20:01
Show Gist options
  • Save 0x09AL/52877728bce71d3c546b5d11cd63da6d to your computer and use it in GitHub Desktop.
Save 0x09AL/52877728bce71d3c546b5d11cd63da6d to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <iostream>
bool a(std::string& str, const std::string& from, const std::string& to) {
size_t start_pos = str.find(from);
if(start_pos == std::string::npos)
return false;
str.replace(start_pos, from.length(), to);
return true;
}
void replace(std::string& str, const std::string& from, const std::string& to) {
if(from.empty())
return;
size_t start_pos = 0;
while((start_pos = str.find(from, start_pos)) != std::string::npos) {
str.replace(start_pos, from.length(), to);
start_pos += to.length();
}
}
int main(){
char ch;
std::string FILENAME;
printf("\033[1;33;40m******************************\nWelcome to the International Dealing Program - v2\n******************************\n");
printf("We fixed the directory traversal from last year so they can't hack us anymore.\n");
while(1){
printf("Enter the country deals you want to see :\nExample: Kosovo, Albania or provide other country.\nCountry > ");
// Read the file
std::cin >> FILENAME;
replace(FILENAME, "../", "");
FILENAME = "/tmp/" + FILENAME ;
FILENAME.append(".txt");
FILE *fp=fopen(FILENAME.c_str(), "r");
if(fp == NULL){
perror("Failed");
return 0;
}
while((ch = fgetc(fp)) != EOF){
printf("%c", ch);
}
fclose(fp);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment