From 032161d2d0a51306f3562da46a6dee2062f55686 Mon Sep 17 00:00:00 2001 From: lowzj Date: Sat, 2 May 2020 00:47:50 +0800 Subject: [PATCH] bugfix: infinite loop in dfget/config/config.go#checkOutput Signed-off-by: lowzj --- dfget/config/config.go | 2 +- dfget/config/config_test.go | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/dfget/config/config.go b/dfget/config/config.go index cc2344e58..bd0e21e13 100644 --- a/dfget/config/config.go +++ b/dfget/config/config.go @@ -304,7 +304,7 @@ func checkOutput(cfg *Config) error { for dir := cfg.Output; !stringutils.IsEmptyStr(dir); dir = filepath.Dir(dir) { if err := syscall.Access(dir, syscall.O_RDWR); err == nil { break - } else if os.IsPermission(err) { + } else if os.IsPermission(err) || dir == "/" { return fmt.Errorf("user[%s] path[%s] %v", cfg.User, cfg.Output, err) } } diff --git a/dfget/config/config_test.go b/dfget/config/config_test.go index ff82c905e..180ae9ce7 100644 --- a/dfget/config/config_test.go +++ b/dfget/config/config_test.go @@ -104,7 +104,9 @@ func (suite *ConfigSuite) TestAssertConfig(c *check.C) { {clog: clog, url: "htt://a", checkFunc: errortypes.IsInvalidValue}, {clog: clog, url: "htt://a.b.com", checkFunc: errortypes.IsInvalidValue}, {clog: clog, url: "http://a.b.com", output: "/tmp/output", checkFunc: errortypes.IsNilError}, + {clog: clog, url: "http://a.b.com", output: "./root", checkFunc: errortypes.IsNilError}, {clog: clog, url: "http://a.b.com", output: "/root", checkFunc: errortypes.IsInvalidValue}, + {clog: clog, url: "http://a.b.com", output: "/", checkFunc: errortypes.IsInvalidValue}, } var f = func() (err error) { @@ -139,6 +141,7 @@ func (suite *ConfigSuite) TestCheckOutput(c *check.C) { {"", "zj.test", j("zj.test")}, {"", "/tmp", ""}, {"", "/tmp/a/b/c/d/e/zj.test", "/tmp/a/b/c/d/e/zj.test"}, + {"", "/", ""}, } if cfg.User != "root" {