Commit f6cff078 authored by Shamil Garatuev's avatar Shamil Garatuev Committed by Alex Brainman

windows/registry: improve ReadSubKeyNames permissions

The existing implementation requires QUERY_VALUE and ENUMERATE_SUB_KEYS permissions to enumerate
subkeys, so, using registry key name limits, Stat function could be excluded
from methods body and improved method requires only ENUMERATE_SUB_KEYS permission

Registry elements size limits described there:
https://msdn.microsoft.com/library/windows/desktop/ms724872.aspx

Fixes golang/go#23869

Change-Id: Id96beb9b0b294f01cc6eb1bb53bee5f50d02ea7e
Reviewed-on: https://go-review.googlesource.com/95655Reviewed-by: 's avatarAlex Brainman <alex.brainman@gmail.com>
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 88d2dcc5
...@@ -113,12 +113,10 @@ func OpenRemoteKey(pcname string, k Key) (Key, error) { ...@@ -113,12 +113,10 @@ func OpenRemoteKey(pcname string, k Key) (Key, error) {
// The parameter n controls the number of returned names, // The parameter n controls the number of returned names,
// analogous to the way os.File.Readdirnames works. // analogous to the way os.File.Readdirnames works.
func (k Key) ReadSubKeyNames(n int) ([]string, error) { func (k Key) ReadSubKeyNames(n int) ([]string, error) {
ki, err := k.Stat() names := make([]string, 0)
if err != nil { // Registry key size limit is 255 bytes and described there:
return nil, err // https://msdn.microsoft.com/library/windows/desktop/ms724872.aspx
} buf := make([]uint16, 256) //plus extra room for terminating zero byte
names := make([]string, 0, ki.SubKeyCount)
buf := make([]uint16, ki.MaxSubKeyLen+1) // extra room for terminating zero byte
loopItems: loopItems:
for i := uint32(0); ; i++ { for i := uint32(0); ; i++ {
if n > 0 { if n > 0 {
......
...@@ -29,7 +29,7 @@ func randKeyName(prefix string) string { ...@@ -29,7 +29,7 @@ func randKeyName(prefix string) string {
} }
func TestReadSubKeyNames(t *testing.T) { func TestReadSubKeyNames(t *testing.T) {
k, err := registry.OpenKey(registry.CLASSES_ROOT, "TypeLib", registry.ENUMERATE_SUB_KEYS|registry.QUERY_VALUE) k, err := registry.OpenKey(registry.CLASSES_ROOT, "TypeLib", registry.ENUMERATE_SUB_KEYS)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment