Przeglądaj źródła

Also filter out some other obviously invalid filenames (ref #1243)

Jakob Borg 11 lat temu
rodzic
commit
9a45f0b31c
2 zmienionych plików z 10 dodań i 6 usunięć
  1. 3 2
      internal/db/leveldb.go
  2. 7 4
      internal/protocol/protocol.go

+ 3 - 2
internal/db/leveldb.go

@@ -587,8 +587,9 @@ func ldbWithAllFolderTruncated(db *leveldb.DB, folder []byte, fn func(device []b
 			panic(err)
 		}
 
-		if f.Name == "" {
-			l.Infoln("Dropping invalid nil filename from database")
+		switch f.Name {
+		case "", ".", "..", "/": // A few obviously invalid filenames
+			l.Infof("Dropping invalid filename %q from database", f.Name)
 			batch := new(leveldb.Batch)
 			ldbRemoveFromGlobal(db, batch, folder, device, nil)
 			batch.Delete(dbi.Key())

+ 7 - 4
internal/protocol/protocol.go

@@ -490,8 +490,9 @@ func (c *rawConnection) handleIndexUpdate(im IndexMessage) {
 func filterIndexMessageFiles(fs []FileInfo) []FileInfo {
 	var out []FileInfo
 	for i, f := range fs {
-		if f.Name == "" {
-			l.Infoln("Dropping nil filename from incoming index")
+		switch f.Name {
+		case "", ".", "..", "/": // A few obviously invalid filenames
+			l.Infof("Dropping invalid filename %q from incoming index", f.Name)
 			if out == nil {
 				// Most incoming updates won't contain anything invalid, so we
 				// delay the allocation and copy to output slice until we
@@ -500,8 +501,10 @@ func filterIndexMessageFiles(fs []FileInfo) []FileInfo {
 				out = make([]FileInfo, i, len(fs)-1)
 				copy(out, fs)
 			}
-		} else if out != nil {
-			out = append(out, f)
+		default:
+			if out != nil {
+				out = append(out, f)
+			}
 		}
 	}
 	if out != nil {