• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2021 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5package main
6
7/*
8#include <stdlib.h>
9#include <stdio.h>
10
11int *p;
12int* test() {
13 p = (int *)malloc(2 * sizeof(int));
14 free(p);
15 return p;
16}
17*/
18import "C"
19import "fmt"
20
21func main() {
22	// C passes Go an invalid pointer.
23	a := C.test()
24	// Use after free
25	*a = 2 // BOOM
26	// We shouldn't get here; asan should stop us first.
27	fmt.Println(*a)
28}
29