-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GetFirmwareEnvironmentVariable(Ex) does not provide a way to know the UEFI variable's size #29
Comments
Thanks for the feedback @sylveon! There are a number of win32 APIs that follow this pattern (this particular API goes all the way back to Windows XP SP1). To change the shape of the API means we'd have to create a new API with a different name (as these are plain C APIs) while keeping the existing ones working as they do today, since we can't break users of these existing APIs. I don't know if there are plans to make a new API to change the calling pattern, but UEFI variables should normally be pretty stable over time though, so I think the potential for race conditions/getting different values across a few calls over a couple milliseconds is pretty small. |
|
@sylveon :) My point though is: In any case, I don't think there is broad applicability to this one API being updated esp. having a working version, so if I had to guess, this API won't see a new version in the near future. |
I agree it's not critical, but a nice to have. In my experience, the APIs following the try again with a bigger buffer pattern will return the size required in some manner upon calling it with a too small or null buffer, so that you only have to call the API twice, not repeatedly until you've got a big enough buffer. For example, GetModuleFileName. While a WinRT API would be nice, I don't think a string is correct because UEFI variables often contain binary data, not strings. |
I guess it can follow the traditional Win32 way of doing things: call the API with NULL which returns the required size, then call it again with a buffer of that size. |
@asklar I'm not familiar with other Win32 APIs that work this way. Which ones are you referring to when you say that? I think you're confusing this reported issue with the (generally accepted) pattern of calling an API twice, first with a zero-sized buffer or nullptr to retrieve the target size. |
Yes, that's the pattern I would expect from the API, not "try again until it hasn't failed" |
Currently, this method and derivatives does not provide a way to know the exact size needed to store the resulting UEFI variable, meaning that the API must be called in a loop until it does not fail - this is bad API design and extremely inefficient.
Most APIs in Windows which can result in variable-sized data provide a way to retrieve its size before, for example GetWindowText has the matching GetWindowTextLength. While this does give the potential for race conditions, repeatedly calling the API in a loop has an even worse potential for race conditions.
The text was updated successfully, but these errors were encountered: