c++ - How the LabWindows CVI detects buffer overflow in C -
yesterday,i find cvi can detect buffer overflow when run simple code in c,which make me confused.
void main(void) { int a[10]; int buf[10]; int test[10]; int *p = &buf[10]; *p = 1; while(1); }
when can run program, error occurred.the message "dereference of out-of-bounds pointer 1 bytes (1 elements) past end of array"(sorry not permission post image)
i confused how implemented,as know c/c++ don't have built-in array boundary. try in other platform vc++6.0 , linux, , no 1 can detect overflow. you.
i've not used labwindows/cvi, brief discussion it, i'm guessing detected out-of-bounds dereference @ runtime, not @ compile-time. static code analysis (correctness checks can performed @ compile-time without running software) limited in types of errors can catch. in simple example, compiler conceivably catch error, cannot catch errors in general case because tracing dataflow combinations of inputs go large program intractable problem powerful supercomputers, if left chew on problem eons.
the way sort of problem can caught in general case dynamic program analysis: automatically instrumenting code runtime boundary checks, and/or executing code through simulator tracks boundaries of memory allocations , verifies accesses against boundaries. example implementation of former strategy ada programming language, mission-critical safety considered far more important performance. in case of ada, language designed permit such checks. implementation of c or c++ languages similar things, existence of raw pointers in language make more difficult , perhaps prohibitively more runtime-expensive.
in c , c++, if want kind of runtime bounds-checking (only testing), might valgrind. know of no other tool that's more thorough in catching out-of-bounds accesses. prepared program run slowly. perhaps labwindows/cvi similar valgrind?
in case, need aware regardless of verification tool use, way catch buggy code runtime bounds-checking if supply input program evokes out-of-bound behavior. absence of bounds-check failures verification tool not definitive indicator program has no such bugs.
Comments
Post a Comment