windows: avoid uint16 overflow in NewNTUnicodeString

Fixes CVE-2026-39824
Fixes #78916

Change-Id: I344518a17d59fd81c4bb39da0b3e13be6a6a6964
Reviewed-on: https://go-review.googlesource.com/c/sys/+/770080
Reviewed-by: Neal Patel <nealpatel@google.com>
Reviewed-by: Quim Muntal <quimmuntal@gmail.com>
LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Damien Neil <dneil@google.com>
This commit is contained in:
Damien Neil
2026-04-23 08:37:02 -07:00
committed by Gopher Robot
parent 94ad893e1e
commit fb1facd76f
2 changed files with 34 additions and 14 deletions
+6 -3
View File
@@ -1697,10 +1697,13 @@ func NewNTUnicodeString(s string) (*NTUnicodeString, error) {
if err != nil {
return nil, err
}
n := uint16(len(s16) * 2)
n := len(s16) * 2
if n > (1<<16)-1 {
return nil, syscall.EINVAL
}
return &NTUnicodeString{
Length: n - 2, // subtract 2 bytes for the NULL terminator
MaximumLength: n,
Length: uint16(n) - 2, // subtract 2 bytes for the NULL terminator
MaximumLength: uint16(n),
Buffer: &s16[0],
}, nil
}