Skip to content

Commit dce5c56

Browse files
committed
libpod: fix nil pointer dereference in getHostsEntries
When NetMode.IsPasta() is true but pastaResult is nil (which can happen during container setup failures or in certain edge cases), accessing c.pastaResult.IPAddresses causes a panic. Add a nil check for c.pastaResult before accessing its fields, matching the pattern used elsewhere in the codebase. Fixes rootless test failures in PR containers#27338. Signed-off-by: Lokesh Mandvekar <[email protected]>
1 parent 3f303c4 commit dce5c56

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

libpod/container_internal_common.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2381,7 +2381,7 @@ func (c *Container) getHostsEntries() etchosts.HostEntries {
23812381
entries = etchosts.GetNetworkHostEntries(c.state.NetworkStatus, names...)
23822382
case c.config.NetMode.IsPasta():
23832383
// this should never be the case but check just to be sure and not panic
2384-
if len(c.pastaResult.IPAddresses) > 0 {
2384+
if c.pastaResult != nil && len(c.pastaResult.IPAddresses) > 0 {
23852385
entries = etchosts.HostEntries{{IP: c.pastaResult.IPAddresses[0].String(), Names: names}}
23862386
}
23872387
default:

0 commit comments

Comments
 (0)