Skip to content

Commit 1496e2f

Browse files
committed
fix: close potential gaps
1 parent eaad607 commit 1496e2f

2 files changed

Lines changed: 19 additions & 4 deletions

File tree

internal/betterdiscord/addons.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,16 @@ func downloadAddon(kind AddonKind, dir, rawURL string) (string, error) {
218218
}
219219

220220
dest := filepath.Join(dir, base)
221+
222+
// Normalize and ensure the destination remains within the addon directory
223+
dest = filepath.Clean(dest)
224+
dirClean := filepath.Clean(dir)
225+
dirWithSep := dirClean + string(os.PathSeparator)
226+
227+
if dest != dirClean && !strings.HasPrefix(dest, dirWithSep) {
228+
return "", fmt.Errorf("resolved addon path is outside the addon directory")
229+
}
230+
221231
if _, err := utils.DownloadFile(rawURL, dest); err != nil {
222232
return "", err
223233
}

internal/betterdiscord/buildinfo.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func (i *BDInstall) ReadBuildinfo() (bi Buildinfo, err error) {
4444

4545
// Compile your regexes
4646
versionRe := regexp.MustCompile(`version:\s?"([0-9]+\.[0-9]+\.[0-9]+)"`)
47-
commitRe := regexp.MustCompile(`commit:\s?"(\b[0-9a-f]{5,40}\b)"`)
47+
commitRe := regexp.MustCompile(`commit:\s?"([0-9a-f]{5,40})"`)
4848
branchRe := regexp.MustCompile(`branch:\s?"([a-zA-Z0-9_\-]+)"`)
4949
modeRe := regexp.MustCompile(`build:\s?"([a-zA-Z]+)"`)
5050

@@ -90,11 +90,16 @@ func (i *BDInstall) ReadBuildinfo() (bi Buildinfo, err error) {
9090
}
9191
}
9292

93-
// Keep last 1 KB as tail (enough for your patterns)
93+
// Keep last 1 KB as tail for next round
94+
// Use a copy to avoid holding onto the entire window
9495
if len(window) > 1024 {
95-
tail = window[len(window)-1024:]
96+
newTail := make([]byte, 1024)
97+
copy(newTail, window[len(window)-1024:])
98+
tail = newTail
9699
} else {
97-
tail = window
100+
newTail := make([]byte, len(window))
101+
copy(newTail, window)
102+
tail = newTail
98103
}
99104
}
100105

0 commit comments

Comments
 (0)