gentoo90 / winreg-rs

Rust bindings to MS Windows Registry API
MIT License
168 stars 36 forks source link

`enum_values` and `enum_keys` creates infinite iterators if you don't open the key with read permissions #43

Open jorgenpt opened 3 years ago

jorgenpt commented 3 years ago

The following code will never terminate (until it runs out of memory):

fn main() {
    if let Ok(key) = winreg::RegKey::predef(HKEY_CURRENT_USER)
        .open_subkey_with_flags(r"SOFTWARE\Classes\tel", winreg::enums::KEY_SET_VALUE)
    {
        let _: Vec<_> = key.enum_values().collect();
    }
}

While the problem is obvious (you need to include winreg::enums::KEY_READ), the failure case is confusing. It might be more intuitive if enum_values (and presumably enum_keys) returned a single Err for the ERROR_ACCESS_DENIED, returned an empty iterator, or had a return value of io::Result<EnumValues> instead. :)