Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The following problem concerns the following, low-quality code: void foo(int x) { int a[3]; char buf[4]; a[0] = 0xF0F1F2F3; a[1] = x; gets(buf); printf(a[0] =

The following problem concerns the following, low-quality code: void foo(int x) { int a[3]; char buf[4]; a[0] = 0xF0F1F2F3; a[1] = x; gets(buf); printf("a[0] = 0x%x, a[1] = 0x%x, buf = %s ", a[0], a[1], buf); } In a program containing this code, procedure foo has the following disassembled form on an x86/64 machine: 000000000040057d : 40057d: push %rbp 40057e: mov %rsp,%rbp 400581: sub $0x30,%rsp 400585: mov %edi,-0x24(%rbp) 400588: movl $0xf0f1f2f3,-0x10(%rbp) 40058f: mov -0x24(%rbp),%eax 400592: mov %eax,-0xc(%rbp) 400595: lea -0x20(%rbp),%rax 400599: mov %rax,%rdi 40059c: mov $0x0,%eax 4005a1: callq 400480 4005a6: mov -0xc(%rbp),%edx 4005a9: mov -0x10(%rbp),%eax 4005ac: lea -0x20(%rbp),%rcx 4005b0: mov %eax,%esi 4005b2: mov $0x400670,%edi 4005b7: mov $0x0,%eax 4005bc: callq 400450 4005c1: leaveq 4005c2: retq For the following questions, recall that: gets is a standard C library routine that reads the input from a user. x86/64 machines are little-endian. C strings are null-terminated (i.e., terminated by a character with value 0x00). Characters a through z have ASCII codes 0x61 through 0x7a. Consider the case where procedure foo is called with argument x equal to 0xE0E2E4E6, and we type "abcdefghijklmnopqrstu" in response to gets. Fill in each input box at the bottom with your answer to each blank in the following questions. The number before each blank indicates its corresponding input box number. 1. Express where on the stack the following program values are located as hex offsets (positive or negative) relative to register %rbp: Program Value Hex Offset a ________________________ a[2] ________________________ buf ________________________ buf[3] ________________________ 2. What will the printf function print for the following: a[0] (hexadecimal): ________________________ a[1] (hexadecimal): ________________________

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: 3

blur-text-image

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

Time Series Databases New Ways To Store And Access Data

Authors: Ted Dunning, Ellen Friedman

1st Edition

1491914726, 978-1491914724

More Books

Students also viewed these Databases questions

Question

How do Dimensional Database Models differ from Relational Models?

Answered: 1 week ago

Question

What type of processing do Relational Databases support?

Answered: 1 week ago

Question

Describe several aggregation operators.

Answered: 1 week ago