Skip to content

Commit 036b3ab

Browse files
committed
Check symbolic links
1 parent bc8ba8a commit 036b3ab

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

pkg/leeway/provenance.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -295,17 +295,26 @@ type provenanceEnvironment struct {
295295
func (p *Package) inTotoMaterials() ([]in_toto.ProvenanceMaterial, error) {
296296
res := make([]in_toto.ProvenanceMaterial, 0, len(p.Sources))
297297
for _, src := range p.Sources {
298-
stat, err := os.Lstat(src);
298+
stat, err := os.Lstat(src)
299299
if err != nil {
300300
return nil, err
301301
}
302302

303-
if stat.Mode().IsDir() {
303+
if stat.Mode().IsDir() || !stat.Mode().IsRegular() {
304304
continue
305305
}
306306

307-
if !stat.Mode().IsRegular() {
308-
continue
307+
// in case of symlinks, we need to resolve the link and check the target
308+
if stat.Mode()&os.ModeSymlink == os.ModeSymlink {
309+
targetSrc, _ := os.Readlink(src)
310+
stat, err := os.Lstat(targetSrc)
311+
if err != nil {
312+
return nil, err
313+
}
314+
315+
if stat.Mode().IsDir() || !stat.Mode().IsRegular() {
316+
continue
317+
}
309318
}
310319

311320
hash, err := sha256Hash(src)
@@ -341,7 +350,6 @@ func sha256Hash(fn string) (res string, err error) {
341350
return "", xerrors.Errorf("cannot compute hash of %s: %w", fn, err)
342351
}
343352

344-
345353
return fmt.Sprintf("%x", hash.Sum(nil)), nil
346354
}
347355

0 commit comments

Comments
 (0)