Skip to content

Commit 767a9af

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 ce0ef49 commit 767a9af

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
@@ -2350,7 +2350,7 @@ func (c *Container) getHostsEntries() etchosts.HostEntries {
23502350
entries = etchosts.GetNetworkHostEntries(c.state.NetworkStatus, names...)
23512351
case c.config.NetMode.IsPasta():
23522352
// this should never be the case but check just to be sure and not panic
2353-
if len(c.pastaResult.IPAddresses) > 0 {
2353+
if c.pastaResult != nil && len(c.pastaResult.IPAddresses) > 0 {
23542354
entries = etchosts.HostEntries{{IP: c.pastaResult.IPAddresses[0].String(), Names: names}}
23552355
}
23562356
default:

0 commit comments

Comments
 (0)