Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove data races in downloader caused by shared use of json path eval. #547

Merged
merged 1 commit into from
Jun 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions cmd/csaf_downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import (
type downloader struct {
cfg *config
keys *crypto.KeyRing
eval *util.PathEval
validator csaf.RemoteValidator
forwarder *forwarder
mkdirMu sync.Mutex
Expand Down Expand Up @@ -73,7 +72,6 @@ func newDownloader(cfg *config) (*downloader, error) {

return &downloader{
cfg: cfg,
eval: util.NewPathEval(),
validator: validator,
}, nil
}
Expand Down Expand Up @@ -218,17 +216,20 @@ func (d *downloader) download(ctx context.Context, domain string) error {
return fmt.Errorf("invalid URL '%s': %v", lpmd.URL, err)
}

expr := util.NewPathEval()

if err := d.loadOpenPGPKeys(
client,
lpmd.Document,
base,
expr,
); err != nil {
return err
}

afp := csaf.NewAdvisoryFileProcessor(
client,
d.eval,
expr,
lpmd.Document,
base)

Expand Down Expand Up @@ -297,9 +298,10 @@ func (d *downloader) loadOpenPGPKeys(
client util.Client,
doc any,
base *url.URL,
expr *util.PathEval,
) error {

src, err := d.eval.Eval("$.public_openpgp_keys", doc)
src, err := expr.Eval("$.public_openpgp_keys", doc)
if err != nil {
// no keys.
return nil
Expand Down Expand Up @@ -421,6 +423,7 @@ func (d *downloader) downloadWorker(
dateExtract = util.TimeMatcher(&initialReleaseDate, time.RFC3339)
lower = strings.ToLower(string(label))
stats = stats{}
expr = util.NewPathEval()
)

// Add collected stats back to total.
Expand Down Expand Up @@ -588,7 +591,7 @@ nextAdvisory:

// Validate if filename is conforming.
filenameCheck := func() error {
if err := util.IDMatchesFilename(d.eval, doc, filename); err != nil {
if err := util.IDMatchesFilename(expr, doc, filename); err != nil {
stats.filenameFailed++
return fmt.Errorf("filename not conforming %s: %s", file.URL(), err)
}
Expand Down Expand Up @@ -651,7 +654,7 @@ nextAdvisory:
continue
}

if err := d.eval.Extract(
if err := expr.Extract(
`$.document.tracking.initial_release_date`, dateExtract, false, doc,
); err != nil {
slog.Warn("Cannot extract initial_release_date from advisory",
Expand Down
Loading