1
0

1707293949.v1.0.0-3-g8164e8f.adding-filepath-clean-to-address-directory-traversal-2.patch 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. Subject: Adding filepath.Clean to address directory traversal #2
  2. Origin: upstream, https://github.com/openfibernet/tftp-proxy/pull/3
  3. Upstream-Author: Arnoud Vermeer <avermeer@tucows.com>
  4. Date: Wed Feb 7 09:19:09 2024 +0100
  5. --- a/main.go
  6. +++ b/main.go
  7. @@ -4,10 +4,10 @@
  8. "flag"
  9. "fmt"
  10. "io"
  11. - "io/ioutil"
  12. "net/http"
  13. "os"
  14. "path"
  15. + "path/filepath"
  16. "time"
  17. "github.com/pin/tftp"
  18. @@ -18,9 +18,10 @@
  19. // readHandler is called when client starts file download from server
  20. func readHandler(filename string, rf io.ReaderFrom) error {
  21. + file_path := filepath.Clean(path.Join(dir, filename))
  22. - if _, err := os.Stat(path.Join(dir, filename)); err == nil {
  23. - file, err := os.Open(path.Join(dir, filename))
  24. + if _, err := os.Stat(file_path); err == nil {
  25. + file, err := os.Open(file_path)
  26. if err != nil {
  27. fmt.Fprintf(os.Stderr, "%v\n", err)
  28. return err
  29. @@ -50,8 +51,8 @@
  30. defer resp.Body.Close()
  31. if resp.StatusCode != 200 {
  32. - io.Copy(ioutil.Discard, resp.Body)
  33. - return fmt.Errorf("Received status code: %d", resp.StatusCode)
  34. + io.Copy(io.Discard, resp.Body)
  35. + return fmt.Errorf("received status code: %d", resp.StatusCode)
  36. }
  37. rf.(tftp.OutgoingTransfer).SetSize(resp.ContentLength)