Skip to content

Commit 35ef4a9

Browse files
kolyshkingopherbot
authored andcommitted
runtime: x_cgo_getstackbound: initialize pthread attr
In glibc versions older than 2.32 (before commit 4721f95), pthread_getattr_np does not always initialize the `attr` argument, and when it fails, it results in a NULL pointer dereference in pthread_attr_destroy down the road. This is the simplest way to avoid this, and an alternative to CL 585019. Updates #65625. Change-Id: If490fd37020b03eb084ebbdbf9ae0248916426d0 Reviewed-on: https://go-review.googlesource.com/c/go/+/587919 Auto-Submit: Ian Lance Taylor <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Reviewed-by: Cherry Mui <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Cherry Mui <[email protected]>
1 parent 2fe2e4d commit 35ef4a9

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/runtime/cgo/gcc_stack_unix.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,21 @@ x_cgo_getstackbound(uintptr bounds[2])
1818
void *addr;
1919
size_t size;
2020

21+
// Needed before pthread_getattr_np, too, since before glibc 2.32
22+
// it did not call pthread_attr_init in all cases (see #65625).
23+
pthread_attr_init(&attr);
2124
#if defined(__GLIBC__) || (defined(__sun) && !defined(__illumos__))
2225
// pthread_getattr_np is a GNU extension supported in glibc.
2326
// Solaris is not glibc but does support pthread_getattr_np
2427
// (and the fallback doesn't work...). Illumos does not.
2528
pthread_getattr_np(pthread_self(), &attr); // GNU extension
2629
pthread_attr_getstack(&attr, &addr, &size); // low address
2730
#elif defined(__illumos__)
28-
pthread_attr_init(&attr);
2931
pthread_attr_get_np(pthread_self(), &attr);
3032
pthread_attr_getstack(&attr, &addr, &size); // low address
3133
#else
3234
// We don't know how to get the current stacks, so assume they are the
3335
// same as the default stack bounds.
34-
pthread_attr_init(&attr);
3536
pthread_attr_getstacksize(&attr, &size);
3637
addr = __builtin_frame_address(0) + 4096 - size;
3738
#endif

0 commit comments

Comments
 (0)