eBPF-based security platform
upatch_decode: truncate numbers without libm
Daniel Borkmann99a86cb5207d
diff --git a/include/shirudo/misc.h b/include/shirudo/misc.hindex 023b9da3..2c03c953 100644--- a/include/shirudo/misc.h+++ b/include/shirudo/misc.h@@ -2,7 +2,8 @@/** Copyright (c) 2026 Authors of shirudo*- * The kernel's fixed-width integer types and ptr_to_u64(), for userspace.+ * The kernel's fixed-width integer types, ptr_to_u64() and shirudo_trunc(),+ * for userspace.*/#ifndef SHIRUDO_MISC_H@@ -28,4 +29,17 @@ static inline __u64 ptr_to_u64(const void *ptr)return (__u64)(unsigned long)ptr;}+/*+ * trunc() without libm, which clang calls for it and the binaries do+ * not link. A double of 2^52 or more is integral already.+ */+static inline double shirudo_trunc(double x)+{+ if (x == 0 || !(x > -0x1p52 && x < 0x1p52))+ return x;+ if (x < 0)+ return -(double)(__s64)-x;+ return (double)(__s64)x;+}+#endifdiff --git a/util/upatch_decode.c b/util/upatch_decode.cindex 5b2846ec..93809f15 100644--- a/util/upatch_decode.c+++ b/util/upatch_decode.c@@ -482,7 +482,8 @@ static int lua_otel_emit_value(lua_State *L, int idx, struct json_out *out,out->err = -EINVAL;break;}- if (trunc(value) == value && fabs(value) <= max_exact_integer) {+ if (shirudo_trunc(value) == value &&+ fabs(value) <= max_exact_integer) {snprintf(num, sizeof(num), "%.0f", value == 0 ? 0 : value);json_puts(out, "{\"intValue\":");json_put_string(out, num, strlen(num));