Skip to content

Commit

Permalink
fix: return valid byte slice on csaf channel (#43)
Browse files Browse the repository at this point in the history
Send a newly created byte slice with the csaf document content on the
channel. Previously the sent byte slice was gained from the method
`Buffer.Bytes()`. However this "slice is valid for use only until the
next buffer modification" and therefore modified with the next buffer
modification..

## Why

The bug caused a data race. If the receiver is not processing the
content from the channel fast enough, the content of the returned byte
slice is overwritten by the next downloaded CSAF.
  • Loading branch information
mgoetzegb authored Sep 26, 2024
1 parent 6e04b58 commit 2e76e10
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion cmd/csaf_downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"os"
"path"
"path/filepath"
"slices"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -678,7 +679,8 @@ nextAdvisory:
}

if d.cfg.ForwardChannel {
d.Csafs <- data.Bytes()
// the bytes slice is modified by the next buffer modification, so we need to copy it
d.Csafs <- slices.Clone(data.Bytes())
}

if d.cfg.NoStore {
Expand Down

0 comments on commit 2e76e10

Please sign in to comment.