Skip to content

bounds expressions not respected by aliases (core dump) #410

@mwhicks1

Description

@mwhicks1

The following program type checks in checked mode, and yet it will core dump because it permits changing a bounds expression via a pointer. This seems like a serious problem, since it's at the heart of what the type system will/will not support.

#include <stdlib_checked.h>
#include <stdio_checked.h>

#pragma BOUNDS_CHECKED ON

struct p {
  _Array_ptr<char> buf : count(len);
  unsigned int len;
};

void foo(_Ptr<struct p> ptr) {
  unsigned int i;
  for (int i=0; i<ptr->len; i++) {
    ptr->buf[i] = 'a';
    _Unchecked { printf("Assigning index %d an %c\n",i,'a'); }
    ptr->len++;
  }
}

int main(int argc, _Nt_array_ptr<char> argv[] : count(argc)) {
  _Ptr<struct p> p = 0;
  p = malloc(sizeof(struct p));
  p->buf = malloc(10);
  p->len = 10;
  foo(p);
  return 0;
}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions