lab 09 answer sheet - web2.clarkson.edu · lab 09 answer sheet name: _____ return this sheet before...

3
Lab 09 Answer Sheet Name: ______________________ Return this sheet before Friday Afternoon March 13 th 2015. Part I. Array Out of Bounds 1. What are the addresses of the following variables: i _______________________ j _______________________ k _______________________ l ________________________ array _______________________ 2. Look at the last three digits of the addresses above. Convert these from hex to decimal (you can use the calculator). i _______________________ j _______________________ k _______________________ l ________________________ array _______________________ 3. How far apart is array from the closest integer? How far apart are the rest of them? 4. After the line “i = j = k = l = 0;” there are three lines assigning values to the array? Which of these are good assignments and which are problematic assignments? Why?

Upload: lambao

Post on 22-Mar-2019

218 views

Category:

Documents


0 download

TRANSCRIPT

Lab 09 Answer Sheet

Name: ______________________

Return this sheet before Friday Afternoon March 13th 2015.

Part I. Array Out of Bounds

1. What are the addresses of the following variables:

i _______________________ ���

j _______________________ ���

k _______________________

���l ________________________

array _______________________

2. Look at the last three digits of the addresses above. Convert these from hex to decimal (you can use the calculator).

���i _______________________

���j _______________________ ���

k _______________________ ���

l ________________________

array _______________________

3. How far apart is array from the closest integer? How far apart are the rest of them?

4. After the line “i = j = k = l = 0;” there are three lines assigning values to the array? Which of these are good assignments and which are problematic assignments? Why?

asus1
Чистильщик
asus1
Чистильщик
asus1
Пишущая машинка
asus1
Чистильщик
asus1
Пишущая машинка
12:30 pm or send the scans or filled pdf-file to [email protected] until Friday, 11:59 pm
asus1
Пишущая машинка
asus1
Пишущая машинка
asus1
Пишущая машинка
asus1
Пишущая машинка
asus1
Пишущая машинка
asus1
Пишущая машинка
asus1
Пишущая машинка
asus1
Пишущая машинка
asus1
Пишущая машинка
asus1
Пишущая машинка
asus1
Пишущая машинка
asus1
Пишущая машинка
asus1
Пишущая машинка
asus1
Пишущая машинка
asus1
Пишущая машинка
asus1
Пишущая машинка
asus1
Пишущая машинка
asus1
Пишущая машинка

5. After the line “array[12] = 3;” has been executed, what are the values of the following variables?

i __________

���j __________

k __________

l __________

6. Explain Why the variables i, j, k, and l have the above values? Hint: Look at the addresses where we made changes?

Part II. Buffer Overflow

1. What are the addresses of cstring1 and cstring2?

���Cstring1 _________________________

Cstring2 _________________________

2. After we set cstring1 to all x's we have the line “ cstring[15] = '\0' ”. What is '\0' and why do we have this line?

3. What are the values printed for cstring1 and cstring2 after line 59 (cstring2[15] = '\0';)?

Cstring1 ________________________

Cstring2_________________________

4. What are the values stored in the variables cstring1 and cstring2 at the end of the functions? Explain why cstring1 is changed while we only added more values to cstring2.

Cstring1 ________________________ ���

Cstring2_________________________

Part III. Dangerous Code [look at the output by executing a.out]

1. What is the value printed for cstring1 after the first strncpy has been run?

2. What is the value printed for cstring1 after the second strncpy has been run?

3. Why is the first one longer than the second, even though we copied more characters the second time? Hint: What is missing if we only move the first 4 characters?