Skip to content
This repository was archived by the owner on Dec 20, 2024. It is now read-only.

Commit 032161d

Browse files
committed
bugfix: infinite loop in dfget/config/config.go#checkOutput
Signed-off-by: lowzj <[email protected]>
1 parent 0b48f55 commit 032161d

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

dfget/config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ func checkOutput(cfg *Config) error {
304304
for dir := cfg.Output; !stringutils.IsEmptyStr(dir); dir = filepath.Dir(dir) {
305305
if err := syscall.Access(dir, syscall.O_RDWR); err == nil {
306306
break
307-
} else if os.IsPermission(err) {
307+
} else if os.IsPermission(err) || dir == "/" {
308308
return fmt.Errorf("user[%s] path[%s] %v", cfg.User, cfg.Output, err)
309309
}
310310
}

dfget/config/config_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ func (suite *ConfigSuite) TestAssertConfig(c *check.C) {
104104
{clog: clog, url: "htt://a", checkFunc: errortypes.IsInvalidValue},
105105
{clog: clog, url: "htt://a.b.com", checkFunc: errortypes.IsInvalidValue},
106106
{clog: clog, url: "http://a.b.com", output: "/tmp/output", checkFunc: errortypes.IsNilError},
107+
{clog: clog, url: "http://a.b.com", output: "./root", checkFunc: errortypes.IsNilError},
107108
{clog: clog, url: "http://a.b.com", output: "/root", checkFunc: errortypes.IsInvalidValue},
109+
{clog: clog, url: "http://a.b.com", output: "/", checkFunc: errortypes.IsInvalidValue},
108110
}
109111

110112
var f = func() (err error) {
@@ -139,6 +141,7 @@ func (suite *ConfigSuite) TestCheckOutput(c *check.C) {
139141
{"", "zj.test", j("zj.test")},
140142
{"", "/tmp", ""},
141143
{"", "/tmp/a/b/c/d/e/zj.test", "/tmp/a/b/c/d/e/zj.test"},
144+
{"", "/", ""},
142145
}
143146

144147
if cfg.User != "root" {

0 commit comments

Comments
 (0)