Граф коммитов

514 Коммитов

Автор SHA1 Сообщение Дата
Anna Kornfeld Simpson 4e872889cf
Add POSIX socket header (#313)
Adds bounds-safe interfaces for all functions in the POSIX header sys/socket.
2018-09-05 15:35:55 -07:00
Anna Kornfeld Simpson 51a978be38
Bounds safe-interface for function in arpa/inet (#314)
Creates arpa/inet_checked.h with a bounds-safe interface for one function.
2018-09-04 17:33:57 -07:00
Anna Kornfeld Simpson f54ca6710b
Fixing a typo in the snprintf_array_ptr definition.
Typo was not caught before because my checkedc tests build got corrupted and I had to rebuild clang and the checkedc tests from scratch. The tests caught the typo. (#312)
2018-08-28 20:25:29 -07:00
Anna Kornfeld Simpson 69369e5534
Propose change to snprintf bounds-safe interface (#309)
Change the snprintf bounds-safe interface.
By default, the destination of snprintf is null-terminated and therefore has bounds one-less than the second argument.
Add a second bounds-safe interface for when snprintf destination is an array_ptr only; this one is in checkedc_extensions.
2018-08-28 13:51:56 -07:00
Prabhuk 9272f587a8
Polymorphic bounds safe interface stdlib functions. (#306)
Changed the signature of malloc, calloc and free to make them polymorphic bounds safe interface functions and fixed the tests that failed due to the change in signature.
2018-08-28 13:49:05 -07:00
Anna Kornfeld Simpson ee4fe9ec39
Adds bounds-safe interface for __assert_fail on Linux (#310)
Adds to assert_checked.h a bounds-safe interface for __assert_fail
2018-08-28 13:43:24 -07:00
Anna Kornfeld Simpson a502de195c
Unistd file commands (#308)
* Add access, read, and write bounds safe interfaces to unistd_checked
2018-08-28 13:42:39 -07:00
David Tarditi d49f31caea
Tests for parsing and typechecking return_value expression. (#302)
This changes add tests for parsing and type checking of return_value expressions.  This matches the compiler pull request at https://github.com/Microsoft/checkedc-clang/pull/544.
2018-08-18 22:50:18 -07:00
Prabhuk 154733b005
Adding support for polymorphic bounds safe interface functions. (#303)
Added tests for polymorphic bounds interface functions.
2018-08-16 10:27:22 -07:00
Anna Kornfeld Simpson 3fcdbbb800
Bounds-safe interface for assert (#299)
New header with bounds-safe interface for a function called by assert macros on both Windows and Linux.
2018-08-08 16:58:06 -07:00
Anna Kornfeld Simpson 2ad18c7e10
memmove should not have restrict on arguments. (#301)
By spec, memmove allows the dest and src arguments to point to overlapping areas of memory. Restrict indicates that the programmer has enforced that the arguments do not point to overlapping areas of memory. Thus, memmove should not have restrict.
2018-08-08 16:42:13 -07:00
Anna Kornfeld Simpson 03871e5efd
Change the bounds-safe interface of free to byte_count 0.
Changes the original bounds-safe interface of free to byte_count of 0. We no longer need the extra version of free in checkedc_extensions. Fixes #290.
2018-08-03 09:18:31 -07:00
Anna Kornfeld Simpson f506955558
Bounds-safe interface for function in errno (#294)
Adds errno_checked.h with bounds-safe interfaces for the functions that both Windows and Linux use in their errno macros. Includes a simple test.
2018-08-02 09:11:28 -07:00
Anna Kornfeld Simpson 295cd1e286
Add a .gitignore file for executables (#293)
* Add a .gitignore entry for .out files (which may appear in the sample directory)
* Add Windows executables to .gitignore
2018-07-26 09:48:20 -07:00
Anna Kornfeld Simpson 98eca60d11
Add header guards (#295)
* Add header guards.
* Also add guarding to make sure this is not included in C++ compilation. If it is C++, still want to make sure the unchecked version of the header is included.
2018-07-26 09:48:02 -07:00
Prabhuk 8ec52a19da
Validate that _Nt_checked type array initializers are null terminated (#289)
Related Issue: https://github.com/Microsoft/checkedc-clang/issues/397

1. Added test cases for possible ways through which _Nt_initializers arrays can be initialized
2. Added negative test cases (e.g. array initializers without null terminators at the end) for which checkedc clang compiler is expected to report errors
2018-07-24 10:16:50 -07:00
Anna Kornfeld Simpson 12a4b53e9c
New header with additional bounds-safe interfaces (#292)
* Added new extensions header file with bounds safe interfaces for functions whose interfaces differ between array_ptr and nt_array_ptr. Developers can include this checkedc_extensions header and then choose the appropriate interface for each invocation. Since C does not support function overloading, the functions in the checkedc_extensions header have different names, so the developer will have to rename their function calls.
* Added comments in the existing header files to point to the alternates in the new files. We currently have alternates for free() and strncmp().
* Added the new header to the test that includes all the headers.

Addresses #290 and #291
2018-07-24 10:04:31 -07:00
Anna Kornfeld Simpson 80d0555ad9
The unistd_checked.h header was missing from the build. Add it to CMakeLists.txt (#288) 2018-07-17 13:45:31 -07:00
Shen Liu 360a48bb8c
add initializers for initialization required variables, and some test cases for array/struct/union unit testing. (#287)
Add test cases to test whether an array, or an object of struct/union type that contains a checked value is initialized
2018-06-28 15:08:21 -07:00
David Tarditi 8b08ff3111
Update version number to 0.8 draft (#286)
Update specification version number to a draft version of 0.8.
2018-06-08 08:40:44 -07:00
David Tarditi b1853bfb72
Update version number to 0.7.1 (#285)
Finalize version 0.7.1. of the specification.
2018-06-08 08:26:28 -07:00
David Tarditi 95aa444265
Test restrictions on taking addresses of members and variables. (#284)
Checked C restricts taking the addresses of:
1. Members with member bounds declarations.
2. Members used in member bounds declarations.
3. Variables with bounds declarations.
4. Variables/variable members used in bounds declarations.

This add tests of restrictions 1-3, as part of implementing https://github.com/Microsoft/checkedc-clang/issues/213 and https://github.com/Microsoft/checkedc-clang/issues/212:
- Taking the address of non-array members with or used in bounds declarations is now an error. 
- Taking the address of non-array members with or used in bounds-safe interfaces is allowed in unchecked scopes.  It is an error in checked scopes.
- Taking the address of non-array variables with bounds declaration is now an error.

It is OK to take the address of an array variable or member because you can't use the resulting pointer to modify the pointer that the array converts to.

The trickier cases to test involve nested members.  Given 
```
struct NestedLen {
   int len; 
};

struct S {
   struct NestedLen n;
   _Array_ptr<int> p : count(n.len);
}
```
we don't allow the addresses of `n` or `n.len` to be taken.  However, if `NestedLen` is not embedded in `S`, we allow the address of a struct of type NestedLen to be taken.
2018-05-21 15:19:06 -07:00
David Tarditi ba42d19fa4
Update README.md
Fix typo.
2018-05-09 12:58:47 -07:00
David Tarditi d2ac1647ca
Update README.md
Add a pointer to the Wiki and make the README more concise.
2018-05-09 12:56:05 -07:00
David Tarditi 1768c2ae2a
Update specification to match implementation. (#283)
I plan to release an updated version of the spec because the BOUNDS_CHECKED pragma has been renamed to CHECKED_SCOPE.  Address some other issues where the specification doesn't match the implementation.
- Address issue #100 (update motivation and definitions of explicit dynamic check).  Add a statement that for dynamic_check(e), e must be nonmodifying.
- Address issue #269.  Update specification to allow an interop type and a bounds expression as part of a bounds-safe interface.
- Change the wording to be clear that bounds-safe interface can be applied to unchecked arrays too.  This addresses some feedback in issue #272.
- Remove the requirement that every parameter for a function or every member of a struct/member must be annotated with a bounds-safe interface, if one of them is annotated.  The checking as implemented actually works on a per parameter/per member basis.  Requiring that everything be converted could get in the way of incremental conversion.
2018-05-03 21:07:33 -07:00
David Tarditi f464045e92
Rename BOUNDS_CHECKED pragma to CHECKED_SCOPE. (#282)
Update specification and tests.
2018-04-26 16:31:50 -07:00
David Tarditi 88b6837940
Test uses of functions that return function pointers with bounds-safe interfaces. (#281)
The compiler crashed when `signal` with a bounds-safe interface was called in a checked scope.  PR https://github.com/Microsoft/checkedc-clang/pull/483 fixes this.    This change adds more tests of type checking of functions that return function pointers, including testing uses in and outside of checked scopes.
2018-04-26 13:40:47 -07:00
David Tarditi b2cb9fc5af
Improve tests for function pointers casts. (#280)
A programmer reported that a function call involving a const member with checked function pointer type resulted in an unexpected compiler error (https://github.com/Microsoft/checkedc-clang/issues/481).   This is due to a compiler bug.  This change improves the testing of function pointer casts.
- Add tests of assignments to members with function pointer types.
- Add tests of calls via members with function pointer types.
- Add tests of uses of const members with function pointer types.  These
  uses include member reads, member writes, and indirect calls via members.
- Add case from programmer bug report.
- Spot check uses of members with bounds-safe interfaces that are checked
  function pointer types.

C provides no way to ensure that function pointer casts are correct.  It allows casts between function pointers with different numbers of arguments, for example, which can result in crashes involving corrupted stack pointers.

Checked C restricts casts to checked function pointer to ensure that values are actually valid function pointers.  For example, casts from a variable with an unchecked function pointer type to a checked function pointer type is not allowed.  The variable with unchecked type could have been
corrupted via an incorrect function pointer cast.  Checked C allows casts from declared functions, null pointers, and values with checked pointer types. It also allows casts via value-preserving casts and cast-like operations applied to these expressions.  (address-of and dereference of function pointer types are value-preserving operations).
2018-04-24 16:28:19 -07:00
David Tarditi e83d877d83
Test disallowing inferred bounds expressions with modifying expressions. (#278)
The current specification rules for inferring bounds for an expression can lead to inferred bounds that contain modifying expression.   These aren't allowed.  Add tests that check that the compiler is flagging them  (the Checked C version of clang suggests that the programmer use a temporary variable when this happens).

The particular problematic case that is likely to arise in practice is for member access: `e1.f` and `e1->f`.  If e1 contains a side-effect, we can't expression that bounds for `f` when other members are involved:
```
struct S {
  array_ptr<int> p : count(len);
  int len;
};
```
`e1 ->p` `has `bounds(e1->p, e1->p + e1->len)`.  This is problematic if `e1` has side-effects.   Note that the case where only `e1->p` is involved isn't a problem because we can use `current_expr_value`.
2018-04-21 12:44:09 -07:00
David Tarditi 4ed7e4b9b1
Update README.md 2018-04-17 12:06:41 -07:00
David Tarditi 29aed58ce9
Update readme.md for repo. (#276)
Add a pointer to the compiler installer.
2018-04-13 15:26:21 -07:00
David Tarditi bd0b56889b
Improve Checked C samples (#275)
This adds several small programs to the Checked C samples directory that show some common tasks.  It includes the canonical "hello, world" program, how to catch a runtime check failure and exit gracefully, and how to avoid a compile-time warning by using a dynamic check.    It also includes an intentionally buggy program.  The README.md file explains the programs.   

Several of those sample programs are for code examples in the new Checked C clang users manual. The change also moves samples taken from the specification to a subdirectory.
2018-04-13 14:32:57 -07:00
David Tarditi 57353d9e23
Checking of bounds declarations everywhere, expression equality facts. (#273)
This matches a compiler change that turns on checking of bounds declarations everywhere and teaches the compiler about simple equality facts.

Checking of bounds declarations is a static analysis that checks that declared bounds are valid (follow from existing bounds and other information in the environment). It was only on by default for checked scopes.  It is now on by default for unchecked scopes too.   The checking of bounds declarations is still simple, so it may produce unnecessary warnings.   It can be turned off using  `-Wno-check-bounds-decls` (everywhere), `-Wno-check-bounds-decl-unchecked-scope` (for unchecked scopes), and `-Wno-check-bounds-decls-checked-scope` (for checked scopes), 

  - Added more tests of expression equivalence (lexical_equality.c should be renamed because it now tests for expression equivalence using a few additional facts about C expressions).
  - Updated tests to handle the fact that checking of bounds declaration is on everywhere by default.  Replace a bunch of TODO's with expected warning messages. Also deleted some warnings that are no longer issued because the compiler can prove the bounds are valid.
  - Kept checking of bounds declarations on for most tests and only disabled it for some parsing and typechecking tests.
  - In some cases, made simple changes to avoid warnings about bounds declarations (the original cases will be captured in the new Checked C clang repo file test/CheckedC/static-checking/bounds-decl-challenges.c)
2018-04-12 08:48:08 -07:00
David Tarditi 526661dd5d
Test bounds checking of interop types with bounds expressions. (#268)
We recently added compiler support for declaring bounds-safe interfaces that have interop types and bounds expressions.  Add tests of runtime bounds checking involving parameters declared this way.   The variables are declared in unchecked scopes and used in checked scopes.   Add tests for these combinations:

- checked array interop types.  This implies bounds that are the count of the first dimension of the array.
- array_ptr interop types with bounds expressions.
- nt_array_ptr interop types with bounds expressions.

We already had a test of nt_array_ptr with no bounds expression, which implies bounds of count(0).
2018-03-22 10:26:21 -07:00
David Tarditi 0450ed0500
Update to new syntax for bounds_cast expressions. (#267)
Update tests and examples to the new syntax for bounds cast expressions.

We changed bounds cast expressions to take a bounds expression as the
second argument, instead of implicitly inferring the type of bounds
expression from the number of arguments.  This is more verbose but
clearer.  Bounds cast expressions now have two forms:

Op<T>(e1)
Op<T>(e1, bounds-expression)

where Op is one of _Assume_bounds_cast or _Dynamic_bounds_cast
and T must be a pointer type.
2018-03-22 10:01:19 -07:00
David Tarditi bde5699049
Improve runtime tests of dynamic_bounds_cast<ptr<T>> operations. (#266)
A user reported an internal compiler crash (https://github.com/Microsoft/checkedc-clang/issues/458).   This change adds additional testing for the compiler fix (https://github.com/Microsoft/checkedc-clang/pull/466):
- Test failing dynamic_bounds_cast operations that convert to ptr<int>.
- Test passing and failing dynamic_bounds_cast operations that
  convert to ptr<void> and void *.   These casts can fail if the
  source range does not have at least one byte in it.
2018-03-20 13:31:46 -07:00
David Tarditi 7e541848f9
Remove inferred return bounds workarounds. Add inferred parameter bounds tests. (#265)
Remove inferred return bounds workarounds. Add inferred parameter bounds tests:
- Update tests now that the compiler properly infers return bounds of count(0) for nt_array_ptr return types.
- Remove workaround for strtok from checked header files.
- Add more tests of inference of bounds/itypes for parameters.  This includes tests that mix parameter types that are pointers and arrays, as well as tests of inferred bounds of nt_checked arrays parameters.
2018-03-20 08:45:33 -07:00
David Tarditi 5756ca2d21
Update CONTRIBUTING.md
Add request for code reviewers for compiler changes.
2018-03-17 11:18:07 -07:00
Lorenzo Cavallaro f8dfbf486a Text for LowFat Stack Bounds Protection, NDSS17 (#264)
Added paragraph for "Stack Bounds Protection with Low Fat Pointers" (NDSS 2017) as well as a reference to the open source implementation of the research prototype.
2018-03-16 08:35:35 -07:00
Lorenzo Cavallaro adf091298d Stack Object Protection with Low Fat Pointers, NDSS17 (#263)
Added reference to "Stack Object Protection with Low Fat Pointers", NDSS 2017
2018-03-16 08:33:47 -07:00
David Tarditi 7e5012a508
Test interface types combined with bounds expressions. (#261)
- Test parsing and typechecking of bounds-safe interfaces with interface types and bounds expressions.
- Test redeclarations of functions and variables with bounds-safe interfaces with interface typese and bounds expressions.
- Add tests of bounds-safe interface in checked scopes that cover the different forms of bounds expressions.  This includes a test case that covers https://github.com/Microsoft/checkedc-clang/issues/443.
- Add tests of redeclarations involving `nt_array_ptr`.
- Fix bounds-safe interface for `strtok`: the compiler isn't properly inferring that return types of the form `nt_array_ptr<char>` have bounds of `count(0)`.  We can just declare the bounds of `count(0)` for now.
2018-03-15 11:19:35 -07:00
David Tarditi 4b6ad9a4ce
Add dynamic tests of reads/writes via pointers with null-terminated interface types. (#259)
Add runtime testing of reads and writes through pointers with null-terminated interface types.  A pointer with a null-terminated type with no bounds information has a bounds of count(0).  A program can read the element at the pointer and write null.   Other reads/writes will cause bounds checking failures.

I extended bounds-safe-interfaces.c, which runs a sequence of read/tests, expecting conditions to be set properly for the nth test in the sequence to fail.   For bounds-safe interfaces for null-terminated types, we currently have no way to specify a length.  In this case, the bounds are fixed.  Instead, we vary the position where the read/write occurs to force a failure.
2018-02-19 16:28:49 -08:00
David Tarditi 6db8e44b72
Fix undefined reference. Finalize v0.7. (#260)
Mark this as the final draft of version 0.7 and fix an undefined reference.
2018-02-15 10:49:55 -08:00
David Tarditi 47e4d7c72c
Change syntax of *_bounds_cast operators and add examples. (#256)
The existing syntax of the *_bound_cast operators is confusing.  The kind
of bounds being specified is not explicit.  It depends on the number of
arguments to the operator.  It is clearer to just use a bounds expression
to describe the bounds.  That involves a little more typing, but it is
easier to understand and allows programmers to use all the different variants
of bounds expressions.

Add examples of using dynamic_bounds_cast and assume_bounds_cast for
clarity.
2018-02-06 15:24:52 -08:00
David Tarditi 689bc4e709
Improve formatting of code examples in specification. (#254)
This change improves the formatting of code examples in the Checked C specification.  We now use the LaTeX listings package for source code examples and snippets of source code.  This should make the source code easier to read.  We use a similar color scheme to the one used by Visual Studio for C: blue for keywords, light blue for variables, and black for symbolic characters.

The listings package can import examples from source files.   This will let us move larger examples to separate source code files and make sure they compile during automated testing.
2018-02-05 18:23:12 -08:00
David Tarditi 72d9027977
Fix typos found during review of literals section. (#253)
Fix typographical errors in the specification found during a review of the new section on string literals and compound literals.
2018-02-01 13:42:51 -08:00
David Tarditi 40ef91900e
Update description of initialization requirements (#252)
Variables with checked pointer type that may be used to access memory must be initialized when they are declared.  This also applies to variables with members or elements with checked pointer type that may be used to access memory.  Update the specification to make this clear.   Include some examples.  This addresses issue #98.

The compiler already checks these requirements for scalar variables.  I opened https://github.com/Microsoft/checkedc-clang/issues/445 to track checking these requirements for struct and array variables.

Add tests for the struct/array cases to the Checked C tests.
2018-01-31 15:57:22 -08:00
David Tarditi 2ce3b321ad
Update rules for implicit conversions. (#251)
This updates the type checking rules for implicit casts. This addresses issues 
#150 and #206 n the specification.  It removes the subsections for each kind
of cast between pointer kinds and presents a unified framework instead.
- Use a diagram to describe what kinds of pointers can be converted to other
  kinds of pointers.  It is easier to visualize this than to explain in text.
  The conversions form a lattice. We can use this fact to more simply
  describe conversion rules.
- Allow conversions from checked void pointers.  We allow this by necessity
  already in the implementation.  It is needed so that malloc
  can be used in checked code.
- Mention that we plan to replace casts from checked void pointers.
- Move the description of assignment compatibility earlier.

In the description of C-style casts, remove the special case for ptr<void>.
It would be confusing to expand it now that we allow conversions from
array_ptr<void too. State in text instead that the conversions between
checked void pointers are allowed.

Add a description of the type checking rules for conditional expressions.
This was only partly covered, and that description was incomplete.
It is easier to explain this more generally.  Note that the compiler doesn't
quite match the spec.  It doen't allow casts between ptr<T> and array_ptr<T>,
which are now allowed.  I opened Checked C clang issue 444 to cover this.

Update some tests for type checking of conditional expressions to more
precisely check for arm types of the form 'T *' and "checked pointer to void"
that we're not merging them to T *.  This could then be converted to checked
pointer type.  The existing tests would pass and things would look OK, even
though from a typing perspective, it wouldn't be.
2018-01-30 14:42:13 -08:00
David Tarditi 0065a3df41
Checked C typing rules for literals. Also describe handling of initializers. (#249)
Describe extensions to C typing rules that allow literals to be used in checked scopes or where expressions with checked pointers are expected.   This completes the work for issue #207.   For checked scopes, string literals are given the type "null-terminated checked array of character", where "character" is the character type for the string literal.   For contexts where an expression with a checked pointer type is expected but not found, convert string literals and compound array literals to checked pointer types.

Also describe the rules for initializers.   The types of initializer values are determined by the  type of the variable being declared, so there isn't any change needed for Checked C.  

Add examples.

Move the section describing checked scopes earlier in Chapter 2, so that it precedes the discussion of literals (this is most of the change diff shown on GitHub).
2018-01-23 16:52:53 -08:00
David Tarditi 98a6ac5d8f
Return statements with bounds-safe interfaces. (#250)
Update the specification to cover type checking and bounds checking of
return statements with bounds-safe interfaces.
2018-01-23 13:36:33 -08:00