windows: allocate attribute list with LocalAlloc, not individual items

We didn't want to wind up with Go pointers mangled by win32, so we were
previously copying the contents into a LocalAlloc'd blob, and then
adding that to the attribute list. The problem is that recent changes to
the API broke this design convention, to the point where it expects 0x18
byte objects to be added using size 0x8. This seems like an unfortunate
oversight from Microsoft, but there's nothing we can do about it. So we
can work around it by instead LocalAlloc'ing the actual container, and
then using the exact pointer value that's passed into Update.

This commit also adds a test that both makes sure that these functions
actually work, and provokes a UaF that's successfully caught, were you
to comment out the line of this commit that reads `al.pointers =
append(al.pointers, value)`.

Fixes golang/go#50134.

Change-Id: Ib73346d2d6ca3db601cd236596cefb564d9dc8f1
Trust: Jason Donenfeld <>
Run-TryBot: Jason Donenfeld <>
TryBot-Result: Gopher Robot <>
Reviewed-by: Patrik Nyblom <>
Trust: Patrik Nyblom <>
Run-TryBot: Patrik Nyblom <>
3 files changed
tree: 5659d3e46559f4872c7f23f7c3801726150ec9a6
  1. cpu/
  2. execabs/
  3. internal/
  4. plan9/
  5. unix/
  6. windows/
  7. .gitattributes
  8. .gitignore
  10. codereview.cfg
  13. go.mod


Go Reference

This repository holds supplemental Go packages for low-level interactions with the operating system.


The easiest way to install is to run go get -u You can also manually git clone the repository to $GOPATH/src/

Report Issues / Send Patches

This repository uses Gerrit for code changes. To learn how to submit changes to this repository, see

The main issue tracker for the sys repository is located at Prefix your issue with “x/sys:” in the subject line, so it is easy to find.