FinalCS3214S10Solution

FinalCS3214S10Solution - CS 3214 Spring 2010 Final Exam...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
CS 3214 Spring 2010 Final Exam Solutions 1/14 CS 3214 Final Exam Solutions 54 students took the final exam. The table below shows who graded which problem and statistics about it. The exams are kept by your section’s instructor. Arrange by email if you wish to look at your exam. P1 P2 P3 P4 P5 P6 Total Min 0 3 4 1 3 0 26 Max 12 17 26 14 15 16 85 Possible 12 18 24 14 16 16 100 Avg 6.5 9.4 18.3 7.7 8.7 7.4 58.6 StDev 3.5 3.8 5.6 3.3 2.8 4.3 15.8 Median 7 9 19.5 7.5 9 6 60 Grader Godmar Godmar Peter Scott Ali Ali
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS 3214 Spring 2010 Final Exam Solutions 2/14 1. Linking and Loading (12 pts) The following questions are related to linking and loading in a C/Unix environment. a) (4 pts) A coding style rule that is used in many C-based projects is that variables that are used only within one compilation unit be declared static. Sketch briefly how you could create a script as part of the build process that would check if programmers followed this rule! Use nm or a similar tool and verify that for every defined global symbol (recognizable with a capital letter such as ‘T’, ‘C’, or ‘D’ in nm), there exists at least one undefined (‘U’) reference in another .o file. Some answers suggested a source code analysis approach by looking for ‘extern’ declarations. While possible, this is more difficult because simply declaring a variable or function extern does not produce an undefined reference unless the variable or function is actually used. A common mistake was to propose an algorithm that would check that static variables with the same name aren’t used outside the current compilation unit. This is wrong: static variables are local to a compilation unit, so using a static variable with the same name in different files is entirely ok (and occurs quite often). b) (4 pts) Consider the following two .c files: // inck.c extern int k; void inc_k() { k++; } // main.c extern void inc_k(); int main() { inc_k(); return 0; } What error message would the command gcc inck.c main.c -o main produce if one attempted to compile and link this program? $ gcc -Wall inck.c main.c -o main /tmp/cc4HL3gU.o: In function `inc_k': inck.c:(.text+0x4): undefined reference to `k' inck.c:(.text+0xc): undefined reference to `k' collect2: ld returned 1 exit status The symbol ‘k’ is referenced in inck.o, but never defined. ‘extern’ declares, but does not define a symbol.
Background image of page 2
CS 3214 Spring 2010 Final Exam Solutions 3/14 c) (4 pts) Address space randomization is a defensive technique used to increase an attacker’s difficulty of succeeding with overflow attacks that require a priori knowledge of where a program’s data is located in its virtual address space. For instance, the location of the stack and the start of the heap are randomized on modern systems, so that they vary between different runs of a program. Could the location of global variables be similarly randomized? State your assumptions if necessary! No or yes, depending on your assumptions.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 14

FinalCS3214S10Solution - CS 3214 Spring 2010 Final Exam...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online