зеркало из https://github.com/golang/sys.git
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:
Родитель
88d2dcc510
Коммит
f6cff0780e
|
@ -113,12 +113,10 @@ func OpenRemoteKey(pcname string, k Key) (Key, error) {
|
|||
// The parameter n controls the number of returned names,
|
||||
// analogous to the way os.File.Readdirnames works.
|
||||
func (k Key) ReadSubKeyNames(n int) ([]string, error) {
|
||||
ki, err := k.Stat()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
names := make([]string, 0, ki.SubKeyCount)
|
||||
buf := make([]uint16, ki.MaxSubKeyLen+1) // extra room for terminating zero byte
|
||||
names := make([]string, 0)
|
||||
// Registry key size limit is 255 bytes and described there:
|
||||
// https://msdn.microsoft.com/library/windows/desktop/ms724872.aspx
|
||||
buf := make([]uint16, 256) //plus extra room for terminating zero byte
|
||||
loopItems:
|
||||
for i := uint32(0); ; i++ {
|
||||
if n > 0 {
|
||||
|
|
|
@ -29,7 +29,7 @@ func randKeyName(prefix string) string {
|
|||
}
|
||||
|
||||
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 {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче