Skip to content

Commit

Permalink
Merge pull request #66 from credativ/fix_public_list
Browse files Browse the repository at this point in the history
Fix nil pointer dereference when accessing /public/
  • Loading branch information
ntap-fge authored Apr 24, 2024
2 parents 0487b47 + 670a224 commit 7c69638
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions pkg/api/static/static.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ func staticHandler(ctx *macaron.Context, log *log.Logger, opt StaticOptions) boo
}

f, err := opt.FileSystem.Open(file)
fResponse := f
if err != nil {
return false
}
Expand All @@ -154,17 +155,18 @@ func staticHandler(ctx *macaron.Context, log *log.Logger, opt StaticOptions) boo
}

file = path.Join(file, opt.IndexFile)
f, err = opt.FileSystem.Open(file)
fIndex, err := opt.FileSystem.Open(file)
fResponse = fIndex
if err != nil {
return false // Discard error.
}
defer func() {
if err := f.Close(); err != nil {
if err := fIndex.Close(); err != nil {
log.Printf("Failed to close file: %s", err)
}
}()

fi, err = f.Stat()
fi, err = fIndex.Stat()
if err != nil || fi.IsDir() {
return true
}
Expand All @@ -179,7 +181,7 @@ func staticHandler(ctx *macaron.Context, log *log.Logger, opt StaticOptions) boo
opt.AddHeaders(ctx)
}

http.ServeContent(ctx.Resp, ctx.Req.Request, file, fi.ModTime(), f)
http.ServeContent(ctx.Resp, ctx.Req.Request, file, fi.ModTime(), fResponse)
return true
}

Expand Down

0 comments on commit 7c69638

Please sign in to comment.