This commit is contained in:
Sahil Sarwar 2024-11-28 03:03:37 -08:00 committed by GitHub
commit c03f921aa1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -645,7 +645,13 @@ Or you can go back to the classic croc behavior by enabling classic mode:
}
}
if c.String("out") != "" {
if err = os.Chdir(c.String("out")); err != nil {
// validate the path
destPath, err := validateDestPath(c.String("out"))
if err != nil {
return err
}
if err = os.Chdir(destPath); err != nil {
return err
}
}
@ -716,3 +722,20 @@ func relay(c *cli.Context) (err error) {
}
return tcp.Run(debugString, host, ports[0], determinePass(c), tcpPorts)
}
func validateDestPath(path string) (string, error) {
_, err := os.Stat(path)
if err != nil {
// Path doesn't exist, fallback to current directory
currentDir, err := os.Getwd()
if err != nil {
return "", fmt.Errorf("could not get current directory: %w", err)
}
log.Debugf("Path %s does not exist, falling back to current directory: %s", path, currentDir)
fmt.Println("Target directory doesn't exist, receiving in current directory")
// flush the stdout buffer
os.Stdout.Sync()
return currentDir, nil
}
return path, nil
}