Skip to content

armgit / ARTEX

Public Imported from GitHub
0

ARTEX - AI autonomous penetration testing system (English translation; upstream: Autumn-27/ARTEX, AGPL-3.0)

fix(hookvm): compare a float with an integer without truncating it

Leo Camus4cb1cd74049d
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8c6ced3..1f9e00b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,7 @@ All notable changes to this project are documented in this file. The format is b
- **Notification delivery ignores HTTP_PROXY**: the dial guard checks the address it connects to. An environment proxy made that address the proxy, so a link-local target could still be reached. Notification HTTP now connects directly.
- **Captured traffic blobs are owner-only**: HTTP and raw-stream bodies spilled out of the database are written `0600`, and their bucket directory is `0700`. An existing blob is tightened when it is seen again.
- **Asset URLs drop userinfo when parsing fails**: a URL `url.Parse` rejects is no longer stored unchanged. The `scheme://userinfo@` prefix is removed first, so a password in that prefix does not land in the asset row.
+- **Hook `==` keeps the fraction of a float**: comparing a float with an integer truncated the float first, so `1.5 == 1` and `-0.5 == 0` were true. A number decoded by `json.Decode` is a float, so a hook testing `m["amount"] == 0` matched `{"amount":0.5}`. A float on either side is now compared as a float.
- **Hook `range` counts against the memory budget**: ranging over a body, slice, string, or map charges the iteration before the loop. A body larger than the hook budget now stops with the memory limit instead of allocating one element at a time with no check.
- **Chat upload name search stops**: choosing `name`, `name-1`, `name-2`, … now returns an error when the filesystem rejects the path or after 10000 collisions, instead of looping while `Stat` keeps failing.
- **Uploads do not follow a symlink**: chat and workspace uploads `Lstat` the destination and refuse to write when it is already a symlink. A dangling link is no longer treated as a free name.
diff --git a/traffic/hookvm/eval.go b/traffic/hookvm/eval.go
index 26b5d07..8688560 100644
--- a/traffic/hookvm/eval.go
+++ b/traffic/hookvm/eval.go
@@ -1087,6 +1087,11 @@ func valuesEqual(a, b any) bool {
if a == nil || b == nil {
return a == b
}
+ if isFloat(a) || isFloat(b) {
+ af, aok := toFloat(a)
+ bf, bok := toFloat(b)
+ return aok && bok && af == bf
+ }
if an, ok := toInt(a); ok {
if bn, ok := toInt(b); ok {
return an == bn
@@ -1107,6 +1112,16 @@ func toInt(v any) (int64, bool) {
return 0, false
}
+func toFloat(v any) (float64, bool) {
+ if f, ok := v.(float64); ok {
+ return f, true
+ }
+ if n, ok := toInt(v); ok {
+ return float64(n), true
+ }
+ return 0, false
+}
+
func isFloat(v any) bool { _, ok := v.(float64); return ok }
func (e *vm) bool(v any) bool {
diff --git a/traffic/hookvm/vm_test.go b/traffic/hookvm/vm_test.go
index 6527774..ff864e9 100644
--- a/traffic/hookvm/vm_test.go
+++ b/traffic/hookvm/vm_test.go
@@ -451,3 +451,30 @@ func OnRequest(req *Request) error {
}
}
}
+
+func TestEqualityKeepsFloatFraction(t *testing.T) {
+ src := `package hook
+func mark(b bool) string {
+ if b {
+ return "T"
+ }
+ return "F"
+}
+func OnRequest(req *Request) error {
+ x := 1.5
+ n := 1
+ req.SetHeader("X-Eq", mark(x == 1)+mark(x != n)+mark(-0.5 == 0)+mark(2.0 == 2)+mark(n == 1.0))
+ return nil
+}`
+ prog, err := Compile("request", src)
+ if err != nil {
+ t.Fatal(err)
+ }
+ req := &Request{}
+ if err := prog.RunRequest(context.Background(), req, RunOptions{}); err != nil {
+ t.Fatal(err)
+ }
+ if got := req.Headers["X-Eq"][0]; got != "FTFTT" {
+ t.Fatalf("X-Eq = %q, want FTFTT", got)
+ }
+}