mirror of https://github.com/containers/podman.git
Merge pull request #26217 from mheon/fix_26168
Fix SQLite volume lookup queries matching too liberally
This commit is contained in:
commit
dad0b294d4
|
@ -39,13 +39,16 @@ const (
|
||||||
sqliteOptionForeignKeys = "&_foreign_keys=1"
|
sqliteOptionForeignKeys = "&_foreign_keys=1"
|
||||||
// Make sure that transactions happen exclusively.
|
// Make sure that transactions happen exclusively.
|
||||||
sqliteOptionTXLock = "&_txlock=exclusive"
|
sqliteOptionTXLock = "&_txlock=exclusive"
|
||||||
|
// Enforce case sensitivity for LIKE
|
||||||
|
sqliteOptionCaseSensitiveLike = "&_cslike=TRUE"
|
||||||
|
|
||||||
// Assembled sqlite options used when opening the database.
|
// Assembled sqlite options used when opening the database.
|
||||||
sqliteOptions = "db.sql?" +
|
sqliteOptions = "db.sql?" +
|
||||||
sqliteOptionLocation +
|
sqliteOptionLocation +
|
||||||
sqliteOptionSynchronous +
|
sqliteOptionSynchronous +
|
||||||
sqliteOptionForeignKeys +
|
sqliteOptionForeignKeys +
|
||||||
sqliteOptionTXLock
|
sqliteOptionTXLock +
|
||||||
|
sqliteOptionCaseSensitiveLike
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewSqliteState creates a new SQLite-backed state database.
|
// NewSqliteState creates a new SQLite-backed state database.
|
||||||
|
@ -2210,7 +2213,9 @@ func (s *SQLiteState) LookupVolume(name string) (*Volume, error) {
|
||||||
return nil, define.ErrDBClosed
|
return nil, define.ErrDBClosed
|
||||||
}
|
}
|
||||||
|
|
||||||
rows, err := s.conn.Query("SELECT Name, JSON FROM VolumeConfig WHERE Name LIKE ? ORDER BY LENGTH(Name) ASC;", name+"%")
|
escaper := strings.NewReplacer("\\", "\\\\", "_", "\\_", "%", "\\%")
|
||||||
|
queryString := escaper.Replace(name) + "%"
|
||||||
|
rows, err := s.conn.Query("SELECT Name, JSON FROM VolumeConfig WHERE Name LIKE ? ESCAPE '\\' ORDER BY LENGTH(Name) ASC;", queryString)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("querying database for volume %s: %w", name, err)
|
return nil, fmt.Errorf("querying database for volume %s: %w", name, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,4 +114,14 @@ var _ = Describe("Podman volume rm", func() {
|
||||||
Expect(session).Should(ExitCleanly())
|
Expect(session).Should(ExitCleanly())
|
||||||
Expect(len(session.OutputToStringArray())).To(BeNumerically(">=", 2))
|
Expect(len(session.OutputToStringArray())).To(BeNumerically(">=", 2))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("podman volume rm by unique partial name - case & underscore insensitive", func() {
|
||||||
|
volNames := []string{"test_volume", "test-volume", "test", "Test"}
|
||||||
|
for _, name := range volNames {
|
||||||
|
podmanTest.PodmanExitCleanly("volume", "create", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
podmanTest.PodmanExitCleanly("volume", "rm", volNames[0])
|
||||||
|
podmanTest.PodmanExitCleanly("volume", "rm", volNames[2])
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue