mirror of
https://github.com/rwinkhart/sys.git
synced 2026-09-01 14:47:28 -04:00
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/95655 Reviewed-by: Alex Brainman <alex.brainman@gmail.com> Run-TryBot: Alex Brainman <alex.brainman@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
committed by
Alex Brainman
parent
88d2dcc510
commit
f6cff0780e
@@ -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 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user