Question
Please see the source code below written in C++. Can you make the code print Hello World! by providing it with an input string? You
Please see the source code below written in C++. Can you make the code print Hello World! by providing it with an input string? You are NOT allowed to modify the source code. Compile the code with g++. Submit your input string and the screenshot proving that the code prints Hello World!.
Update: Mac OS loads the executable to a random memory location for security reasons like this. The technology is called Address Space Layout Randomization (ASLR, http://en.wikipedia.org/wiki/Address_space_layout_randomization). The implication to the homework is that the address of function f2 will be different every time it is executed. This makes accomplishing the homework very difficult if not impossible. There is a g++ linker option that prevents linker from generating position independent executable (pie). Mac OS loader will then load the executable generated in this way to a fixed position. You can use following command to generate the executable: g++ -Wl,-no_pie -o bof.out bof.cpp
Update: Starting from Microsoft Vista, Windows OS also uses ASLR. There are many resources online. I havent tested them. But you can try some of the methods online to finish the homework.
Sourcecode: #include#include using namespace std; char *p; void f1() { char str[8]; p = str; cout << "Please enter a string:"; while (!cin.eof()) { cin.get(*p); p++; } cout << "The string you entered is:" << str << endl; } void f2() { cout << "Hello World! "; } int main() { cout << sizeof(char*) << endl; cout << (void*) f2 << endl; f1(); return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started