eBPF-based security platform
hex: drop the cap test hex_decode_max() can never fail
Daniel Borkmann40bf6806af32
diff --git a/testing/proofs/cbmc/hex-model.c b/testing/proofs/cbmc/hex-model.cindex 0fac53f2..bc9b7f2f 100644--- a/testing/proofs/cbmc/hex-model.c+++ b/testing/proofs/cbmc/hex-model.c@@ -126,7 +126,7 @@ static void decode_max_is_model(bool huge)s = any_string(len);ret = hex_decode_max(s, out, cap, &n);k = min(len, model_size_add(model_size_mul(cap, 2), 1));- model = !(k % 2) && k / 2 <= cap && model_decode(s, len, k / 2, want);+ model = !(k % 2) && model_decode(s, len, k / 2, want);__CPROVER_assert(ret == (model ? 0 : -EINVAL), "decodeMax's result");if (!ret)__CPROVER_assert(n == k / 2 && !memcmp(out, want, n),diff --git a/testing/proofs/lean4/Shirudo/Hex.lean b/testing/proofs/lean4/Shirudo/Hex.leanindex 7190ac65..33773779 100644--- a/testing/proofs/lean4/Shirudo/Hex.lean+++ b/testing/proofs/lean4/Shirudo/Hex.lean@@ -73,7 +73,7 @@ def decode (s : List Nat) (n : Nat) : Option (List Nat) :=length of what it yields is `*len`. -/def decodeMax (s : List Nat) (cap : Nat) : Option (List Nat) :=let n := min s.length (sizeAdd (sizeMul cap 2) 1)- if n % 2 ≠ 0 ∨ n / 2 > cap then none else decode s (n / 2)+ if n % 2 ≠ 0 then none else decode s (n / 2)/-- A hex digit of either case. -/def isHex (c : Nat) : Bool := (nibble c).isSomediff --git a/util/hex.c b/util/hex.cindex 9dd21844..5945c457 100644--- a/util/hex.c+++ b/util/hex.c@@ -76,7 +76,7 @@ int hex_decode_max(const char *hex, __u8 *out, size_t cap, size_t *len)size_t n = strnlen(hex, size_add(size_mul(cap, 2), 1));int ret;- if (n % 2 || n / 2 > cap)+ if (n % 2)return -EINVAL;ret = hex_decode(hex, out, n / 2);if (!ret)