Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The following program, written in C, writes data all over the data section, star

ID: 3736594 • Letter: T

Question

The following program, written in C, writes data all over the data section, starting from the local variable i. Compile and run the program, then answer the questions. Note that the results vary with different compilers and operating systems, so specify the systems you used. Note the behavior of the while loop. The first statement in the loop (*j=0;) writes a zero to the RAM address stored in variable j. The second statement (j=j-1;) moves the address downward in RAM each time the loop executes. Each step of j moves by a “short integer,” which is 2 bytes (16 bits) long. main() { short i, *j; j = &i; while(1) { *j = 0; j = j-1; } } (a) Describe what happens when the program runs. (b)Does the program behave differently if we store a nonzero value in the first statement in the while loop? For example, substitute 21845 (in hex, 0x5555, alternating 0s and 1s). Describe what happens. Try another numerical value and describe what happens. (c) Does the program behave differently if we add 1 instead of subtracting 1 in the second statement? Try it while storing zeros and find out. Describe what happens. (d)Repeat part (c), but use a nonzero value as described in part (b). (e) Write a program that reads text into an input buffer that is 10 bytes long. Run the program and type in 20 bytes. What happens? Do you get a different result if you use a different language, for example, C versus Java? (f) Look up information about the Morris worm. Identify other vulnerabilities that the worm used to propagate. The following program, written in C, writes data all over the data section, starting from the local variable i. Compile and run the program, then answer the questions. Note that the results vary with different compilers and operating systems, so specify the systems you used. Note the behavior of the while loop. The first statement in the loop (*j=0;) writes a zero to the RAM address stored in variable j. The second statement (j=j-1;) moves the address downward in RAM each time the loop executes. Each step of j moves by a “short integer,” which is 2 bytes (16 bits) long. main() { short i, *j; j = &i; while(1) { *j = 0; j = j-1; } } (a) Describe what happens when the program runs. (b)Does the program behave differently if we store a nonzero value in the first statement in the while loop? For example, substitute 21845 (in hex, 0x5555, alternating 0s and 1s). Describe what happens. Try another numerical value and describe what happens. (c) Does the program behave differently if we add 1 instead of subtracting 1 in the second statement? Try it while storing zeros and find out. Describe what happens. (d)Repeat part (c), but use a nonzero value as described in part (b). (e) Write a program that reads text into an input buffer that is 10 bytes long. Run the program and type in 20 bytes. What happens? Do you get a different result if you use a different language, for example, C versus Java? (f) Look up information about the Morris worm. Identify other vulnerabilities that the worm used to propagate. The following program, written in C, writes data all over the data section, starting from the local variable i. Compile and run the program, then answer the questions. Note that the results vary with different compilers and operating systems, so specify the systems you used. Note the behavior of the while loop. The first statement in the loop (*j=0;) writes a zero to the RAM address stored in variable j. The second statement (j=j-1;) moves the address downward in RAM each time the loop executes. Each step of j moves by a “short integer,” which is 2 bytes (16 bits) long. main() { short i, *j; j = &i; while(1) { *j = 0; j = j-1; } } (a) Describe what happens when the program runs. (b)Does the program behave differently if we store a nonzero value in the first statement in the while loop? For example, substitute 21845 (in hex, 0x5555, alternating 0s and 1s). Describe what happens. Try another numerical value and describe what happens. (c) Does the program behave differently if we add 1 instead of subtracting 1 in the second statement? Try it while storing zeros and find out. Describe what happens. (d)Repeat part (c), but use a nonzero value as described in part (b). (e) Write a program that reads text into an input buffer that is 10 bytes long. Run the program and type in 20 bytes. What happens? Do you get a different result if you use a different language, for example, C versus Java? (f) Look up information about the Morris worm. Identify other vulnerabilities that the worm used to propagate.

Explanation / Answer

This means that once you write your C program, you must run it through a C compiler to turn your program into an executable that the computer can run (execute). The C program is the human-readable form, while the executable that comes out of the compiler is the machine-readable and executable form. What this means is that to write and run a C program, you must have access to a C compiler. If you are using a UNIX machine (for example, if you are writing CGI scripts in C on your host's UNIX computer, or if you are a student working on a lab's UNIX machine), the C compiler is available for free. It is called either "cc" or "gcc" and is available on the command line. If you are a student, then the school will likely provide you with a compiler -- find out what the school is using and learn about it. If you are working at home on a Windows machine, you are going to need to download a free C compiler or purchase a commercial compiler. A widely used commercial compiler is Microsoft's Visual C++ environment (it compiles both C and C++ programs). Unfortunately, this program costs several hundred dollars. If you do not have hundreds of dollars to spend on a commercial compiler, then you can use one of the free compilers available on the Web

Let's start with the simplest possible C program and use it both to understand the basics of C and the C compilation process. Type the following program into a standard text editor (vi or emacs on UNIX, Notepad on Windows or TeachText on a Macintosh). Then save the program to a file named samp.c. If you leave off .c, you will probably get some sort of error when you compile it, so make sure you remember the .c. Also, make sure that your editor does not automatically append some extra characters (such as .txt) to the name of the file. Here's the first program:

When executed, this program instructs the computer to print out the line "This is output from my first program!" -- then the program quits. You can't get much simpler than that!

To compile this code, take the following steps: