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

internal/syscall/windows/registry: improve ReadSubKeyNames permissions

Make ReadSubKeyNames work even if key is opened with only
ENUMERATE_SUB_KEYs access rights mask.

Fixes #23869

Change-Id: I138bd51715fdbc3bda05607c64bde1150f4fe6b2
Reviewed-on: https://go-review.googlesource.com/97435Reviewed-by: default avatarAlex Brainman <alex.brainman@gmail.com>
parent 403ab0f2
...@@ -93,12 +93,10 @@ func OpenKey(k Key, path string, access uint32) (Key, error) { ...@@ -93,12 +93,10 @@ func OpenKey(k Key, path string, access uint32) (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 {
......
...@@ -28,7 +28,7 @@ func randKeyName(prefix string) string { ...@@ -28,7 +28,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