summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsigsegv7 <ian@vegaa.systems>2023-09-18 04:04:30 -0400
committersigsegv7 <ian@vegaa.systems>2023-09-18 04:04:30 -0400
commit9bace888ea4a4c57e1cf00494cb9db0c91a99045 (patch)
tree45cd5ade946e5c3b5cadbb2d9f3debcdd7d92322 /src
parent0f0daf1a917d527748e57ac320a52fd2f00b3335 (diff)
Fix overflow issue + odd behaviour
It is best to check for an overflow risk and lower the step BEFORE we actually perform the inversion Signed-off-by: sigsegv7 <ian@vegaa.systems>
Diffstat (limited to 'src')
-rw-r--r--src/main.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/main.c b/src/main.c
index 259b294..a42d05b 100644
--- a/src/main.c
+++ b/src/main.c
@@ -152,6 +152,11 @@ encrypt(const struct cpu_info *info, char *buf, size_t buf_size)
assert((step & 1) == 0 && step <= 16);
}
+ /* Ensure we don't cause any overflows */
+ while (((current_pos + step) >= buf_size) && step > 1)
+ /* Essentially divide the step by 2, just faster */
+ step >>= 1;
+
switch (step) {
case 16:
accel_invert128((uintptr_t)buf + current_pos);
@@ -171,11 +176,6 @@ encrypt(const struct cpu_info *info, char *buf, size_t buf_size)
}
current_pos += step;
-
- /* Ensure we don't cause any overflows */
- while (((current_pos + step) >= buf_size) && step > 1)
- /* Essentially divide the step by 2, just faster */
- step >>= 1;
}
}