logo

Solution Question 1: 1) 2) 3) 4).

Identify and fix errors in a program, and illustrate the use of printf() function to print memory locations.

2 Pages340 Words68 Views
   

Added on  2023-01-23

Solution Question 1: 1) 2) 3) 4).

Identify and fix errors in a program, and illustrate the use of printf() function to print memory locations.

   Added on 2023-01-23

ShareRelated Documents
Solution
Question 1:
1) In line 4, “size_t i” should be “size_t int i"
2) In line 7, “i=1” should be “i=0”
3) In line 7, “i<11” should be “i<10”
4) Line 10 should not be a part of the code.
Question 2:
The first, second and third chunks of memory are allocated in line no 6,7 and 8 using malloc function
Bytes needed for first memory chunk= 82.5
Bytes needed for second memory chunk= 27.5
Bytes needed for third memory chunk= 15
The first and third values are garbage, the second value is second hence result will be second
argument passed
Question 3
1) Input given : 5, bravo
Where len=5 and src= bravo
Output= br
Value of variable len=5 and size=1
2) The program would have an abnormal run if len is less than 3.
To fix the vulnerability we need to add the following after line no 3:
If size<= 0
{
Return;
}
Question 4
1) Comments are as follows
Line 2: //3 char arrays
Line 3 & line 4: //declaring integer
Line 5: //value of aaa is copied to aaddr
Line 6: //will print the value of aaddr ie 16
Line 7: //will go to a new line
Solution Question 1: 1) 2) 3) 4)._1

End of preview

Want to access all the pages? Upload your documents or become a member.

Related Documents
Common Errors in C Programming and How to Fix Them
|6
|1243
|342

Secure Systems Programming
|13
|1507
|3

Understanding Buffer Overflow: Stack and Heap Buffer Overflows, Exploiting Buffer Overflow, JOP and ROP
|11
|1080
|283

Secure Systems Programming: Coursework 2
|10
|2518
|90

Secure Programming in C
|14
|2158
|367

Understanding Operating Systems: Memory Management and TLB in a Nutshell
|7
|870
|248