+20
-2
lines changedFilter options
+20
-2
lines changed Original file line number Diff line number Diff line change
@@ -672,9 +672,27 @@ func relPath(basedir, path string) string {
672
672
return target
673
673
}
674
674
675
+
func cleanDBName(dbname string) string {
676
+
// We do not want a database name starting with a dot to avoid creating hidden files
677
+
if strings.HasPrefix(dbname, ".") {
678
+
dbname = "_" + dbname
679
+
}
680
+
681
+
// If there is a path separator in the database name, we do not want to
682
+
// create the dump in a subdirectory or in a parent directory
683
+
if strings.ContainsRune(dbname, os.PathSeparator) {
684
+
dbname = strings.ReplaceAll(dbname, string(os.PathSeparator), "_")
685
+
}
686
+
687
+
return dbname
688
+
}
689
+
675
690
func formatDumpPath(dir string, timeFormat string, suffix string, dbname string, when time.Time) string {
676
691
var f, s, d string
677
692
693
+
// Avoid attacks on the database name
694
+
dbname = cleanDBName(dbname)
695
+
678
696
d = dir
679
697
if dbname != "" {
680
698
d = strings.Replace(dir, "{dbname}", dbname, -1)
Original file line number Diff line number Diff line change
@@ -58,7 +58,7 @@ func purgeDumps(directory string, dbname string, keep int, limit time.Time) erro
58
58
return fmt.Errorf("could not purge %s: %s", dirpath, err)
59
59
}
60
60
61
-
if strings.HasPrefix(f[0].Name(), dbname+"_") &&
61
+
if strings.HasPrefix(f[0].Name(), cleanDBName(dbname)+"_") &&
62
62
(!f[0].IsDir() || strings.HasSuffix(f[0].Name(), ".d")) {
63
63
dirContents = append(dirContents, f[0])
64
64
}
@@ -101,7 +101,7 @@ func purgeRemoteDumps(repo Repo, directory string, dbname string, keep int, limi
101
101
// remote path along with any subdirectory. So we have to include it in
102
102
// the filter when listing remote files
103
103
dirpath := filepath.Dir(formatDumpPath(directory, "", "", dbname, time.Time{}))
104
-
prefix := relPath(directory, filepath.Join(dirpath, dbname))
104
+
prefix := relPath(directory, filepath.Join(dirpath, cleanDBName(dbname)))
105
105
106
106
files, err := repo.List(prefix)
107
107
if err != nil {
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4