1
0
mirror of https://github.com/tw93/Mole.git synced 2026-03-22 17:55:08 +00:00

fix(timeout): inherit helper state and pass checks

This commit is contained in:
Tw93
2026-03-14 08:32:11 +08:00
parent 0d2f217f28
commit 169be1e1f2
3 changed files with 21 additions and 15 deletions

View File

@@ -8,6 +8,7 @@ import (
"os"
"os/exec"
"path/filepath"
"slices"
"sort"
"strings"
"sync/atomic"
@@ -165,10 +166,8 @@ func validatePath(path string) error {
return fmt.Errorf("path contains null bytes")
}
// Check for path traversal attempts (.. components).
for _, component := range strings.Split(path, string(filepath.Separator)) {
if component == ".." {
return fmt.Errorf("path contains traversal components: %s", path)
}
if slices.Contains(strings.Split(path, string(filepath.Separator)), "..") {
return fmt.Errorf("path contains traversal components: %s", path)
}
return nil
}

View File

@@ -275,23 +275,22 @@ func getAPFSContainerFreeBytes(mountpoint string) (uint64, error) {
}
const key = "<key>APFSContainerFree</key>"
idx := strings.Index(out, key)
if idx == -1 {
_, rest, found := strings.Cut(out, key)
if !found {
return 0, fmt.Errorf("APFSContainerFree not found")
}
rest := out[idx+len(key):]
start := strings.Index(rest, "<integer>")
if start == -1 {
_, rest, found = strings.Cut(rest, "<integer>")
if !found {
return 0, fmt.Errorf("APFSContainerFree value not found")
}
rest = rest[start+len("<integer>"):]
end := strings.Index(rest, "</integer>")
if end == -1 {
value, _, found := strings.Cut(rest, "</integer>")
if !found {
return 0, fmt.Errorf("APFSContainerFree end tag not found")
}
val, err := strconv.ParseUint(strings.TrimSpace(rest[:end]), 10, 64)
val, err := strconv.ParseUint(strings.TrimSpace(value), 10, 64)
if err != nil {
return 0, fmt.Errorf("failed to parse APFSContainerFree: %v", err)
}