vss: fix potential crash (not reachable in restic)#3045
vss: fix potential crash (not reachable in restic)#3045MichaelEischer merged 6 commits intorestic:masterfrom
Conversation
|
Wouldn't it be cleaner to return an error from initializeVssCOMInterface when it gets a nil? Just asking, I've no idea what the effect on HasSufficientPrivilegesForVSS would be. |
Actually the HRESULT code is correct and fall back to |
|
I'm not sure what you mean. Is there a case where oleIUnknown is nil but still usable? I.e., is the following incorrect? // initializeCOMInterface initialize an instance of the VSS COM api
func initializeVssCOMInterface() (*ole.IUnknown, uintptr, error) {
vssInstance, err := loadIVssBackupComponentsConstructor()
if err != nil {
return nil, 0, err
}
// ensure COM is initialized before use
ole.CoInitializeEx(0, ole.COINIT_MULTITHREADED)
var oleIUnknown *ole.IUnknown
result, _, _ := vssInstance.Call(uintptr(unsafe.Pointer(&oleIUnknown)))
if oleIUnknown == nil {
return nil, 0, errors.Errorf("VSS: got nil OLE object") // or whatever
}
return oleIUnknown, result, nil
} |
|
Ideally |
|
@DRON-666 PR? |
|
Yes @greatroar, I should write PR, but problem is that my developer skills predates git, github and golang. I want to contribute to this project, but definitely not today. |
|
I've cleaned it up. It now handles errors in initializeVssCOMInterface() properly. I've tested it by removing the call to HasSufficientPrivilegesForVSS(). This leads to a to expected error: |
After that |
|
@DRON-666 To make it clean we should also move the error handling in the switch statement into initializeVssCOMInterface(). I'd like to keep the special error handling telling the user about necessary privileges or being an administrator for easy troubleshooting. |
|
I've move error handling to initializeVssCOMInterface(). It will still return a the result because it is needed in HasSufficientPrivilegesForVSS(). |
|
Is there much left to do on this or is it ready for merging soon? |
|
I'm right now thinking about @DRON-666's remarks. |
|
Let us know when you're done :) |
|
Just waiting for @DRON-666 approve my changes. |
|
I also thought about it but I can't easily get around it. Its essentially an implementation detail. In case multiple other things might fail before permissions are checked the API might return a different error. All other possible errors won't give any information about permissions. Actually checking for correct permissions is a bit more involved on windows. I implemented this in #2875 which is still open for discussion. |
The cleanest fix would be to let |
|
The only call site turns a false result into a fatal error anyway, so just returning the error would be enough :) |
Yes and code from cmd_backup.go should be Now it's convert |
|
HasSufficientPrivilegesForVSS() now returns only an error |
|
@DRON-666 and @greatroar Does your thumbs-up clickety-clicks mean that you have no further comments on this PR, that you think it's fine to merge? |
HasSufficientPrivilegesForVSS() now returns an error
What does this PR change? What problem does it solve?
This fixes a potential crash in the VSS code. This is currently not reachable because restic checks for sufficient permissions before calling this code. If used somewhere this ends up dereferencing nil.
Was the change discussed in an issue or in the forum before?
Mentioned in #2274 by @tigerwill90
Checklist
changelog/unreleased/that describes the changes for our users (template here)gofmton the code in all commits