MCPcopy
hub / github.com/ossf/scorecard / GetFile

Method GetFile

internal/gitfile/gitfile.go:158–174  ·  view source on GitHub ↗
(filename string)

Source from the content-addressed store, hash-verified

156}
157
158func (h *Handler) GetFile(filename string) (*os.File, error) {
159 if err := h.setup(); err != nil {
160 return nil, fmt.Errorf("setup: %w", err)
161 }
162
163 // check for path traversal
164 path := filepath.Join(h.tempDir, filename)
165 if !strings.HasPrefix(path, filepath.Clean(h.tempDir)+string(os.PathSeparator)) {
166 return nil, errPathTraversal
167 }
168
169 f, err := os.Open(path)
170 if err != nil {
171 return nil, fmt.Errorf("open file: %w", err)
172 }
173 return f, nil
174}
175
176func (h *Handler) Cleanup() error {
177 if err := os.RemoveAll(h.tempDir); err != nil && !os.IsNotExist(err) {

Callers 4

TestHandlerFunction · 0.95
TestHandlerPathTraversalFunction · 0.95
GetFileReaderMethod · 0.80

Calls 1

setupMethod · 0.95

Tested by 2

TestHandlerFunction · 0.76
TestHandlerPathTraversalFunction · 0.76