1124 detaching threads at any point in time a thread

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: Reading Uninitialized Memory While .bss memory locations (such as uninitialized global C variables) are always initialized to zeros by the loader, this is not true for heap memory. A common error is to assume that heap memory is initialized to zero: 552 1 2 3 4 5 6 7 8 9 10 11 12 CHAPTER 10. VIRTUAL MEMORY /* return y = Ax */ int *matvec(int **A, int *x, int n) { int i, j; int *y = (int *)Malloc(n * sizeof(int)); for (i = 0; i < n; i++) for (j = 0; j < n; j++) y[i] += A[i][j] * x[j]; return y; } In this example, the programmer has incorrectly assumed that vector y has been initialized to zero. A correct implementation would zero y[i] between lines 8 and 9, or use calloc. 10.11.3 Allowing Stack Buffer Overflows As we saw in Section 3.13, a program has a buffer overflow bug if it writes to a target buffer on the stack without the size of the input string. For example, the following function has a buffer overflow bug because the gets function copies an arbitrary length string to the buffer. To fix this, we would need to the use the fgets function, which limits the size of the input string. 1 2 3 4 5 6 7 vo...
View Full Document

This note was uploaded on 09/02/2010 for the course ELECTRICAL 360 taught by Professor Schultz during the Spring '10 term at BYU.

Ask a homework question - tutors are online