Skip to content

Commit 251635c

Browse files
committed
Fix sync issue related to Path Traversal
Signed-off-by: Yussuf Shaikh <[email protected]>
1 parent b057b4c commit 251635c

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

pkg/device/device.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,15 +206,20 @@ func (d *Device) createLinuxDevice() (err error) {
206206

207207
// scsiHostRescan: scans all scsi hosts.
208208
func scsiHostRescan() error {
209-
scsiPath := "/sys/class/scsi_host/"
209+
scsiPath := "/sys/class/scsi_host"
210210
dirs, err := os.ReadDir(scsiPath)
211211
if err != nil {
212212
return err
213213
}
214214
for _, f := range dirs {
215-
name := filepath.Clean(scsiPath + f.Name() + "/scan")
215+
name := f.Name()
216+
// Reject any suspicious names
217+
if strings.Contains(name, "..") || strings.ContainsAny(name, "/\\") {
218+
continue
219+
}
220+
path := filepath.Join(scsiPath, name, "scan")
216221
data := []byte("- - -")
217-
if err := os.WriteFile(name, data, 0666); err != nil {
222+
if err := os.WriteFile(path, data, 0666); err != nil {
218223
return fmt.Errorf("scsi host rescan failed: %v", err)
219224
}
220225
}

0 commit comments

Comments
 (0)