Return error detaching table, only use primary database #6373
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Osquery can fail to detach existing tables when an extension has gone away. This then causes issues re-registering the extension tables when the extension was added back. We can see here that the call to detach will always return success: https://github.com/osquery/osquery/blob/master/osquery/sql/sql.cpp#L162 instead this should return a status stating why it failed.
The reason the detach fails is because it doesn't necessarily use the primary database when calling it. The fix has already been applied to attach function: https://github.com/osquery/osquery/blob/master/osquery/sql/sqlite_util.cpp#L247