Skip to content

Instantly share code, notes, and snippets.

@dmadisetti
Last active August 29, 2015 14:25
Show Gist options
  • Save dmadisetti/b0b6985d2d2df64040d8 to your computer and use it in GitHub Desktop.
Save dmadisetti/b0b6985d2d2df64040d8 to your computer and use it in GitHub Desktop.
Buffer overflow curiosity

# Done like this because it's closest to what I have in prod
main: test.o
g++ -g test.o -o test;
test.o: test.cpp
g++ -c -g test.cpp;
#include <fstream>
#include <iostream>
#define INTBLOCK 1
using namespace std;
std::ifstream file;
streampos pointer;
// Play with the comments and you'll see what I mean
int integer(){
int x;//= 0;
file.seekg (pointer, ios::beg);
file.read ((char*)&x, INTBLOCK);
pointer += INTBLOCK;
//cout << x;
//cout << "\n";
return x;
}
int main(){
pointer = 0;
file.open("file", ios::in|ios::binary|ios::ate);
int count = integer();
int ints[count] = { };
for (int i = 0; i < count; ++i) {
ints[i] = integer();
}
for (int i = 0; i < count; ++i) {
cout << ints[i];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment