Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_step_2

Step: 3

blur-text-image_step3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Objects And Databases International Symposium Sophia Antipolis France June 13 2000 Revised Papers Lncs 1944

Authors: Klaus R. Dittrich ,Giovanna Guerrini ,Isabella Merlo ,Marta Oliva ,M. Elena Rodriguez

2001st Edition

ISBN: 3540416641, 978-3540416647

More Books

Students also viewed these Databases questions

Question

If x 2 -4=12 the what is x=?

Answered: 1 week ago