-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/dist: add asan tests for global objects in testsanitizers package
Add tests to test that -asan in Go can detect the error memory access to the global objects. Updates #44853. Change-Id: I612a048460b497d18389160b66e6f818342d3941 Reviewed-on: https://go-review.googlesource.com/c/go/+/321716 Run-TryBot: Fannie Zhang <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Reviewed-by: Keith Randall <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Benny Siegert <[email protected]>
- Loading branch information
1 parent
0bd7408
commit d544591
Showing
6 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright 2022 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package main | ||
|
||
/* | ||
#include <stdlib.h> | ||
#include <stdio.h> | ||
int test(int *a) { | ||
a[2] = 300; // BOOM | ||
return a[2]; | ||
} | ||
*/ | ||
import "C" | ||
|
||
import "fmt" | ||
|
||
var cIntArray [2]C.int | ||
|
||
func main() { | ||
r := C.test(&cIntArray[0]) | ||
fmt.Println("r value = ", r) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright 2022 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package main | ||
|
||
/* | ||
#include <stdlib.h> | ||
#include <stdio.h> | ||
struct ss { | ||
int *p; | ||
int len; | ||
int cap; | ||
}; | ||
int test(struct ss *a) { | ||
struct ss *t = a + 1; | ||
t->len = 100; // BOOM | ||
return t->len; | ||
} | ||
*/ | ||
import "C" | ||
import "fmt" | ||
|
||
var tt C.struct_ss | ||
|
||
func main() { | ||
r := C.test(&tt) | ||
fmt.Println("r value = ", r) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright 2022 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package main | ||
|
||
/* | ||
#include <stdlib.h> | ||
#include <stdio.h> | ||
int test(int *a) { | ||
int* p = a+1; | ||
*p = 10; // BOOM | ||
return *p; | ||
} | ||
*/ | ||
import "C" | ||
import ( | ||
"fmt" | ||
"unsafe" | ||
) | ||
|
||
var cIntV C.int | ||
|
||
func main() { | ||
r := C.test((*C.int)(unsafe.Pointer(&cIntV))) | ||
fmt.Printf("r value is %d", r) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright 2022 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"unsafe" | ||
) | ||
|
||
var intGlo int | ||
|
||
func main() { | ||
r := bar(&intGlo) | ||
fmt.Printf("r value is %d", r) | ||
} | ||
|
||
func bar(a *int) int { | ||
p := (*int)(unsafe.Add(unsafe.Pointer(a), 1*unsafe.Sizeof(int(1)))) | ||
if *p == 10 { // BOOM | ||
fmt.Println("its value is 10") | ||
} | ||
return *p | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright 2022 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
type Any struct { | ||
s string | ||
b int64 | ||
} | ||
|
||
var Sg = []interface{}{ | ||
Any{"a", 10}, | ||
} | ||
|
||
func main() { | ||
fmt.Println(Sg[0]) | ||
} |