Skip to content

Add non-null checks to pointer arithmetic #237

@secure-sw-dev-bot

Description

@secure-sw-dev-bot

This issue was copied from checkedc/checkedc-clang#237


After some inspection, the call to emit a check should go roughly here

https://github.com/Microsoft/checkedc-clang/blob/master/lib/CodeGen/CGExprScalar.cpp#L2454-L2456

The reason this isn't trivial is that any array_ptr<T> arr : count(x) bounds are translated into array_ptr<T> arr : bounds(arr, arr + x), and we have to do code generation for both the lower and the upper bounds expression. For the upper expression in particular, this will mean we add a non-null check to arr (the "base" pointer). We know this check is redundant, as we do a non-null check of arr before we do the range check.

The sensible fix is probably to disable these non-null checks when generating the code for the upper and lower expressions. It is worth thinking about the soundness of this fix, in particular with respect to range checks that include pointer arithmetic on pointers that aren't the base pointer.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions