mirror of
https://github.com/podman-container-tools/podman.git
synced 2026-10-21 05:17:36 +00:00
sqlite: fix issue in ValidateDBConfig()
If a transaction is started it must either be committed or rolled back. The function uses defer to call `tx.Rollback()` if there is an error returned. However it also called `tx.Commit()` and afterwards further errors can be returned which means it tries to roll back a already committed transaction which cannot work. This fix is to make sure tx.Commit() is the last call in that function. see https://github.com/containers/podman/issues/20731 [NO NEW TESTS NEEDED] Signed-off-by: Paul Holzinger <pholzing@redhat.com>
This commit is contained in:
parent
1e5a1336f8
commit
9c9d2fcaf5
1 changed files with 6 additions and 4 deletions
|
|
@ -378,10 +378,6 @@ func (s *SQLiteState) ValidateDBConfig(runtime *Runtime) (defErr error) {
|
|||
return fmt.Errorf("retrieving DB config: %w", err)
|
||||
}
|
||||
|
||||
if err := tx.Commit(); err != nil {
|
||||
return fmt.Errorf("committing database validation row: %w", err)
|
||||
}
|
||||
|
||||
checkField := func(fieldName, dbVal, ourVal string) error {
|
||||
if dbVal != ourVal {
|
||||
return fmt.Errorf("database %s %q does not match our %s %q: %w", fieldName, dbVal, fieldName, ourVal, define.ErrDBBadConfig)
|
||||
|
|
@ -412,6 +408,12 @@ func (s *SQLiteState) ValidateDBConfig(runtime *Runtime) (defErr error) {
|
|||
return err
|
||||
}
|
||||
|
||||
if err := tx.Commit(); err != nil {
|
||||
return fmt.Errorf("committing database validation row: %w", err)
|
||||
}
|
||||
// Do not return any error after the commit call because the defer will
|
||||
// try to roll back the transaction which results in an logged error.
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue