fix: replace dead len > 2 guard with len != 2 in addSysctl#6883
Open
immanuwell wants to merge 1 commit into
Open
fix: replace dead len > 2 guard with len != 2 in addSysctl#6883immanuwell wants to merge 1 commit into
immanuwell wants to merge 1 commit into
Conversation
strings.SplitN(s, "=", 2) returns at most 2 elements, so the existing len > 2 check never fires. When a sysctl in containers.conf has no '=' the slice has length 1, and the unconditional access to splitn[1] panics. Change the guard to != 2 so a malformed sysctl returns the descriptive error instead of an index-out-of-bounds panic. Signed-off-by: Immanuel Tikhonov <pchpr.00@list.ru> Signed-off-by: immanuwell <pchpr.00@list.ru>
nalind
approved these changes
May 29, 2026
Contributor
nalind
left a comment
There was a problem hiding this comment.
The original version was probably intended to be <, but this works, too.
LGTM, thanks!
Contributor
|
LGTM |
Contributor
|
/lgtm |
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.
What type of PR is this?
What this PR does / why we need it:
strings.SplitN(s, "=", 2)returns at most 2 elements, solen(splitn) > 2inaddSysctlis dead code that never fires. When a sysctl incontainers.confhas no=,splitnhas length 1 andsplitn[1]panics instead of hitting the error return right below.Changing
> 2to!= 2kills the dead code and catches the bad input.How to verify it
Before:
buildah runpanics withindex out of range [1] with length 1After: returns
sysctl "net.core.rmem_max" defined in containers.conf must be formatted name=valueWhich issue(s) this PR fixes:
None
Special notes for your reviewer:
Does this PR introduce a user-facing change?