Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

(Section under construction by Ciera. Just wanted to get some current notes down here before I clean it up.)

Static Analysis

A local analysis should work fine hereWe can catch these with a local flow analysis. We will assume an integer range analysis to track the length of the strings. (Note: I am not entirely familiar with the literature on buffer-overflow analysis, but we should check that all byte string parameters to a method are required to be null terminated and are guaranteed to be null terminated after the function.In the case where it is not required or not guaranteed, we will have to create a separate specificationnone of them already handle this scenario.)

  • Presume that all char* parameters are NT(null-terminated). We must check that they are still NT at the end of the function. Additionally, the return value must be NT. We will also check that they are NT before being passed to another function.
  • Any exceptions to the NT rule (functions that accept/return open strings) are specified separately. Given that this is C, the best option might be two hardcoded handling routines in the analysis. If the function either accepts an open string (not null terminated) or can return an open string, we can write some code to specify this. The analysis calls these handling routines to retrieve these specifications.

...

  • Another option would be to utilize the preprocessor to write in-code specifications. However,

...

  • this is not in the style of C programmers. Additionally, we can't add these specs to libraries that way. Given the environment, a separate specification, in C, is probably the best option.

We also need to assume that there is a string length analysis.

...

  • The integer range analysis tracks the lengths of char*s.
  • We use a tuple lattice for the analysis. The lattice has 4 elements, bottom, NT(null terminating), O(open) and top(unknown).
  • Use the specifications (or the default of NT) to set the initial lattice element for each char*.
  • If we index into the string and set a character to '\0', move the string to NT.

...

  • This only occurs if the index is less than the minimum size of the string.

...

  • (The integer analysis must be aware of strlen and that it works properly only on NT strings.)
  • Check that the parameters to all functions match the specifications. If not, cause an error.
  • At the end of the function, Check that the return value and the parameters match the specification for the function. If not, cause an error

...

  • .

Wiki Markup
There is a question of what to do about character arrays. One option is to assume that char\[\] is open, and using it as a char\* means that we first must make it null terminating. This could get annoying for developers very quickly. I think it's better to treat char\[\] as char*, that is, we assume NT and check for it. If the exception case does occur, it will have to be specified.

This analysis also impacts STR03-A, STR07-A, and STR31-C.

Combined attack (SA/DA/T)

Static analysis to generate test cases, dynamic analysis instruments the code that the test cases run on. Will have slightly different tradeoffs to SA. Good if we don't know the codebase well enough to create the handlers for non-NT functions. More work up front to create this kind of analysis, but reusable to many codebases. Provides the breadth of static analysis, the preciseness of dynamic analysis, and the repeatability of testing. Will have to think through this algorithm more carefully.

Rejected Strategies

Testing

Rejected Strategies

Testing

It would probably be prohibitively expensive to come up with the test cases by hand. Another option is to use a static analysis to generate the test inputs for char*. However, it would still have to generate the inputs for the other values. We would still have to specify whether the function allows open strings or can return open strings, so that the dynamic analysis knows whether to report a defect. Since we still have to write the specifications, this technique will not save developer time thereIt would probably be prohibitively expensive to come up with the test cases by hand.

Dynamic Analysis

It seems the analysis won't be very different from the static analysis, in which case, we should just do this statically.

...