Skip to content

Checked-pointer local variable can be initialized with itself (unsound) #1190

Description

@secure-sw-dev-bot

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


While testing another issue, I made a typo and initialized a checked-pointer local variable with itself and was surprised to find that that compiles without error. An example:

#pragma CHECKED_SCOPE on

int main(void) {
  {
    // Put an invalid pointer in the memory that will be reused by `p`.
    long x = 1;
  }
  {
    _Ptr<char> p = p;
    (*p)++;  // SIGSEGV
  }
  return 0;
}

With -Wall, I get a compiler warning:

self_init.c:9:20: warning: variable 'p' is uninitialized when used within its own initialization [-Wuninitialized]
    _Ptr<char> p = p;
               ~   ^

Maybe this warning just needs to be made into an error when it occurs in the initializer of a checked-pointer variable?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions