-
-
Save dmadisetti/b0b6985d2d2df64040d8 to your computer and use it in GitHub Desktop.
Buffer overflow curiosity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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