File: stack-buffer-overflow-with-position.cpp

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (45 lines) | stat: -rw-r--r-- 2,166 bytes parent folder | download | duplicates (25)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// RUN: %clangxx_asan -O2 %s -o %t
// RUN: not %run %t -2 2>&1 | FileCheck --check-prefix=CHECK-m2 %s
// RUN: not %run %t -1 2>&1 | FileCheck --check-prefix=CHECK-m1 %s
// RUN: %run %t 0
// RUN: %run %t 8
// RUN: not %run %t 9  2>&1 | FileCheck --check-prefix=CHECK-9  %s
// RUN: not %run %t 10 2>&1 | FileCheck --check-prefix=CHECK-10 %s
// RUN: not %run %t 30 2>&1 | FileCheck --check-prefix=CHECK-30 %s
// RUN: not %run %t 31 2>&1 | FileCheck --check-prefix=CHECK-31 %s
// RUN: not %run %t 41 2>&1 | FileCheck --check-prefix=CHECK-41 %s
// RUN: not %run %t 42 2>&1 | FileCheck --check-prefix=CHECK-42 %s
// RUN: not %run %t 62 2>&1 | FileCheck --check-prefix=CHECK-62 %s
// RUN: not %run %t 63 2>&1 | FileCheck --check-prefix=CHECK-63 %s
// RUN: not %run %t 73 2>&1 | FileCheck --check-prefix=CHECK-73 %s
// RUN: not %run %t 74 2>&1 | FileCheck --check-prefix=CHECK-74 %s
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
int main(int argc, char **argv) {
  assert(argc >= 2);
  int idx = atoi(argv[1]);
  char AAA[10], BBB[10], CCC[10];
  memset(AAA, 0, sizeof(AAA));
  memset(BBB, 0, sizeof(BBB));
  memset(CCC, 0, sizeof(CCC));
  int res = 0;
  char *p = AAA + idx;
  printf("AAA: %p\ny: %p\nz: %p\np: %p\n", AAA, BBB, CCC, p);
  // make sure BBB and CCC are not removed;
  return *(short*)(p) + BBB[argc % 2] + CCC[argc % 2];
}
// CHECK-m2: 'AAA'{{.*}} <== {{.*}}underflows this variable
// CHECK-m1: 'AAA'{{.*}} <== {{.*}}partially underflows this variable
// CHECK-9:  'AAA'{{.*}} <== {{.*}}partially overflows this variable
// CHECK-10: 'AAA'{{.*}} <== {{.*}}overflows this variable
// CHECK-30: 'BBB'{{.*}} <== {{.*}}underflows this variable
// CHECK-31: 'BBB'{{.*}} <== {{.*}}partially underflows this variable
// CHECK-41: 'BBB'{{.*}} <== {{.*}}partially overflows this variable
// CHECK-42: 'BBB'{{.*}} <== {{.*}}overflows this variable
// CHECK-62: 'CCC'{{.*}} <== {{.*}}underflows this variable
// CHECK-63: 'CCC'{{.*}} <== {{.*}}partially underflows this variable
// CHECK-73: 'CCC'{{.*}} <== {{.*}}partially overflows this variable
// CHECK-74: 'CCC'{{.*}} <== {{.*}}overflows this variable
// REQUIRES: shadow-scale-3