We will see why this happens shortly before making

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ng of arbitrary length. In general, using gets or any function that can overflow storage is considered a bad programming practice. The C compiler even produces the following error message when compiling a file containing a call to gets: “the gets function is dangerous and should not be used.” 3.13. OUT-OF-BOUNDS MEMORY REFERENCES AND BUFFER OVERFLOW 169 code/asm/bufovf.c 1 2 3 4 5 6 7 8 9 10 11 12 /* This is very low quality code. It is intended to illustrate bad programming practices. See Practice Problem 3.24. */ char *getline() { char buf[8]; char *result; gets(buf); result = malloc(strlen(buf)); strcpy(result, buf); return(result); } code/asm/bufovf.c C Code 1 2 3 4 5 6 7 8 9 10 08048524 <getline>: 8048524: 55 8048525: 89 e5 8048527: 83 ec 10 804852a: 56 804852b: 53 Diagram stack at this point push mov sub push push add lea push call %ebp %esp,%ebp $0x10,%esp %esi %ebx $0xfffffff4,%esp 0xfffffff8(%ebp),%ebx %ebx 80483ac <_init+0x50> 804852c: 804852f: 8048532: 8048533: 83 c4 f4 8d 5d f8 53 e8 74 fe ff ff gets Modify dia...
View Full Document

Ask a homework question - tutors are online