satellite/metabase: add defensive check on copy object
- instead of closing over the outer err variable, potentially overwriting some errors or something, declare local variables. - double check that we got the number of rows we expected to get and error otherwise. this prevents a possible source of inserting bogus rows into the database. Change-Id: I30662be2727afe0a90e4215a182fedc2648d1169
This commit is contained in:
parent
e00423e2e9
commit
3a63939fc9
@ -249,7 +249,7 @@ func (db *DB) FinishCopyObject(ctx context.Context, opts FinishCopyObject) (obje
|
||||
`, originalObject.StreamID, originalObject.SegmentCount))(func(rows tagsql.Rows) error {
|
||||
index := 0
|
||||
for rows.Next() {
|
||||
err = rows.Scan(
|
||||
err := rows.Scan(
|
||||
&positions[index],
|
||||
&expiresAts[index],
|
||||
&rootPieceIDs[index],
|
||||
@ -263,9 +263,14 @@ func (db *DB) FinishCopyObject(ctx context.Context, opts FinishCopyObject) (obje
|
||||
index++
|
||||
}
|
||||
|
||||
if err = rows.Err(); err != nil {
|
||||
if err := rows.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if index != int(originalObject.SegmentCount) {
|
||||
return Error.New("could not load all of the segment information")
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user