Skip to content

Commit 160574d

Browse files
committed
fix potential nil pointer
1 parent 5f6a4fa commit 160574d

File tree

1 file changed

+15
-6
lines changed
  • packages/orchestrator/internal/sandbox/rootfs

1 file changed

+15
-6
lines changed

packages/orchestrator/internal/sandbox/rootfs/nbd.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,21 @@ func (o *NBDProvider) Verify(ctx context.Context) error {
6868
if !o.config.RootfsChecksumVerification {
6969
return nil
7070
}
71-
7271
l := logger.L().With(
73-
zap.String("checksum_expected", hex.EncodeToString(o.overlay.Header().Checksums.Checksum[:])),
7472
logger.WithBuildID(o.overlay.Header().Metadata.BuildId.String()),
7573
)
7674

75+
headerChecksums := o.overlay.Header().Checksums
76+
if headerChecksums == nil {
77+
l.Warn(ctx, "no header checksums to verify")
78+
79+
return nil
80+
}
81+
82+
l = l.With(
83+
zap.String("checksum_expected", hex.EncodeToString(headerChecksums.Checksum[:])),
84+
)
85+
7786
l.Debug(ctx, "verifying rootfs checksum nbd")
7887

7988
checksums, err := o.calculateChecksums(ctx)
@@ -85,15 +94,15 @@ func (o *NBDProvider) Verify(ctx context.Context) error {
8594
zap.String("checksum", hex.EncodeToString(checksums.Checksum[:])),
8695
)
8796

88-
if len(checksums.BlockChecksums) != len(o.overlay.Header().Checksums.BlockChecksums) {
89-
return fmt.Errorf("block checksums length mismatch, expected %d, got %d", len(o.overlay.Header().Checksums.BlockChecksums), len(checksums.BlockChecksums))
97+
if len(checksums.BlockChecksums) != len(headerChecksums.BlockChecksums) {
98+
return fmt.Errorf("block checksums length mismatch, expected %d, got %d", len(headerChecksums.BlockChecksums), len(checksums.BlockChecksums))
9099
}
91100

92101
wrongCount := 0
93102
for blockIndex, blockChecksum := range checksums.BlockChecksums {
94103
blockOffset := header.BlockOffset(int64(blockIndex), o.blockSize)
95104

96-
blockChecksumExpected := o.overlay.Header().Checksums.BlockChecksums[blockIndex]
105+
blockChecksumExpected := headerChecksums.BlockChecksums[blockIndex]
97106
if !bytes.Equal(blockChecksum[:], blockChecksumExpected[:]) {
98107
l.Error(ctx, "rootfs block checksum mismatch nbd",
99108
zap.Int("block_index", blockIndex),
@@ -108,7 +117,7 @@ func (o *NBDProvider) Verify(ctx context.Context) error {
108117
}
109118
}
110119

111-
if !bytes.Equal(checksums.Checksum[:], o.overlay.Header().Checksums.Checksum[:]) {
120+
if !bytes.Equal(checksums.Checksum[:], headerChecksums.Checksum[:]) {
112121
return fmt.Errorf("rootfs checksum mismatch nbd")
113122
}
114123

0 commit comments

Comments
 (0)