Fix osquery version check - #20
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fix osquery version check
Three bugs in the
verifyversion-check path.osqueryVersionComparewas not a SemVer comparisonIt returned
1on the first component whereexisting > requiredwithout first establishing that the higher-order components were equal, so1.9.0compared as newer than2.0.0— and2.0.0vs1.9.0returned1as well. The trailingres := 2fallthrough also meant1.2vs1.2.0reported "required is higher" instead of equal.Now compares component by component after zero-padding, returning at the first difference, and
0when all components are equal.getOsqueryVersioncould panicGuarded
len(splitted) < 2but indexedsplitted[2]— two-field output panicked withindex out of range [2] with length 2. It only worked becauseosqueryd -versionhappens to print three fields.Guard is now
len(fields) < 3. Parsing moved toparseOsqueryVersionso the case is testable without executingosqueryd; usesstrings.Fields, which also drops the separateTrimSpaceand tolerates repeated spaces.An unknown version reported as valid
verifychecked> 1, so the-1error sentinel fell through to logging "osquery version is valid". Now aswitch:2→ too low,-1→ "unknown osquery version", otherwise valid.Tests
Table-driven: 15 cases for the comparison (both directions of
1.9.0/2.0.0, equal, mismatched component counts,5.10.0vs5.9.0to pin numeric-not-lexical ordering, both error sentinels) and 7 for the parse (three-, two-, one-field, empty). Confirmed failing against the pre-fix code.go test ./cmd/osctrld/ -race— 85 pass.golangci-lint run ./...— 0 issues.