Repository navigation
Return errors instead of panicking on short lines in meminfo, ipvs and cpufreq parsers - #880
Open
LemonCondor wants to merge 1 commit into
Open
LemonCondor wants to merge 1 commit into
LemonCondor wants to merge 1 commit into
Conversation
parseMemInfo read fields[1] before checking the field count, so an empty or single-field line panicked instead of returning the existing "Malformed line" error. parseIPVSBackendStatus evaluated fields[1] for any line whose first field is not IP or Prot, panicking on single-field lines. The cpufreq trans_table parser indexed fields[0] on lines made only of whitespace. Check the field count before indexing in all three places. Signed-off-by: Guillaume Marty <yomgui12@outlook.com>
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.
Three parsers index into
strings.Fieldsresults before checking how many fields there are, so malformed input panics withindex out of rangeinstead of returning an error (or skipping the line, where that is what the surrounding code already does):parseMemInforeadsfields[1]before theswitch len(fields)that returnsMalformed line; an empty or single-field line panics. The field count is now checked first, returning the same error.parseIPVSBackendStatusevaluatesfields[1] == "RemoteAddress:Port"for any line whose first field is notIP/Prot; a single-field line panics. The comparison is now guarded bylen(fields) > 1; the other cases already skip short lines.trans_tableparser indexesfields[0]on a line made only of whitespace (it passes theline == ""check). Such lines are now skipped.Tests: added
TestParseMemInfoMalformedLine,TestParseIPVSBackendStatusShortLineandTestParseCpufreqTransTableBlankLine; each panics before this change and passes after.go test ./...passes with the unpacked fixtures;gofmtandgo vetare clean.