fix(unikernels): skip network args in mewz commandstring when no network#674
Open
mdryaan wants to merge 1 commit into
Open
fix(unikernels): skip network args in mewz commandstring when no network#674mdryaan wants to merge 1 commit into
mdryaan wants to merge 1 commit into
Conversation
Mewz.CommandString() unconditionally formatted ip=%s/%d and gateway=%s even when no network was configured, producing "ip=/0 gateway= " as kernel boot parameters. Mewz does not handle this case and panics. Guard the network args behind an m.Net.Address != "" check, matching the existing pattern in Hermit.CommandString(). Add unit tests covering both the no-network and with-network cases. Signed-off-by: mdryaan <alikhurshid4u@gmail.com> Signed-off-by: mdryaan <alikhurshid842001@gmail.com>
✅ Deploy Preview for urunc canceled.
|
cmainas
reviewed
May 14, 2026
Comment on lines
+24
to
+44
| func TestMewzCommandStringNoNetwork(t *testing.T) { | ||
| t.Parallel() | ||
| m := &Mewz{} | ||
| result, err := m.CommandString() | ||
| require.NoError(t, err) | ||
| assert.Equal(t, "", result, "CommandString should return empty string when no network is configured") | ||
| } | ||
|
|
||
| func TestMewzCommandStringWithNetwork(t *testing.T) { | ||
| t.Parallel() | ||
| m := &Mewz{ | ||
| Net: MewzNet{ | ||
| Address: "10.0.0.2", | ||
| Mask: 24, | ||
| Gateway: "10.0.0.1", | ||
| }, | ||
| } | ||
| result, err := m.CommandString() | ||
| require.NoError(t, err) | ||
| assert.Equal(t, "ip=10.0.0.2/24 gateway=10.0.0.1", result) | ||
| } |
Contributor
There was a problem hiding this comment.
Please mere these tests. They are unit tests for the same function.
Comment on lines
+39
to
+44
| var parts []string | ||
| if m.Net.Address != "" { | ||
| parts = append(parts, fmt.Sprintf("ip=%s/%d", m.Net.Address, m.Net.Mask)) | ||
| parts = append(parts, fmt.Sprintf("gateway=%s", m.Net.Gateway)) | ||
| } | ||
| return strings.Join(parts, " "), nil |
Contributor
There was a problem hiding this comment.
No reason to create a slice. It is a simple return of a specific string. So we can just wrap the previous Sprintf in an if statement.
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.
Description
Mewz.CommandString()unconditionally formattedip=%s/%d gateway=%seven when no network was configured, producing"ip=/0 gateway= "as kernel boot parameters. Mewz does not handle this and panics at startup.Guard the network args behind an
m.Net.Address != ""check, matching the pattern already used byHermit.CommandString(). Add unit tests covering both the no-network and with-network cases.Related issues
How was this tested?
Added two unit tests in
pkg/unikontainers/unikernels/mewz_test.go:TestMewzCommandStringNoNetwork: assertsCommandString()returns""when no network is configured.TestMewzCommandStringWithNetwork: assertsCommandString()returns"ip=10.0.0.2/24 gateway=10.0.0.1"when network is configured.Before fix (bug reproduced):

After fix:

LLM usage
N/A
Checklist
make lint).make test_ctr,make test_nerdctl,make test_docker,make test_crictl).