aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2018-09-21 12:54:56 -0500
committerRob Landley <rob@landley.net>2018-09-21 12:54:56 -0500
commit3f98870c621d574cbcbb97a6601229cfc1781c7b (patch)
tree01fb0479aa36b58f39e965cc62d8f1fa4e5c77c0 /main.c
parent2b8a9766d8b4713b63a9a922d7625e9366dff0c1 (diff)
downloadtoybox-3f98870c621d574cbcbb97a6601229cfc1781c7b.tar.gz
Stack can grow in either direction, so needs signed subtraction and abs().
Both positive and both negative should work, even crossing midpoint (which should never happen on linux) works in two's complement.
Diffstat (limited to 'main.c')
-rw-r--r--main.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/main.c b/main.c
index 2d6cc2f8..6f8490ff 100644
--- a/main.c
+++ b/main.c
@@ -156,8 +156,10 @@ void toy_exec_which(struct toy_list *which, char *argv[])
// Compiler writers have decided subtracting char * is undefined behavior,
// so convert to integers. (LP64 says sizeof(long)==sizeof(pointer).)
+ // Signed typecast so stack growth direction is irrelevant: we're measuring
+ // the distance between two pointers on the same stack, hence the labs().
if (!CFG_TOYBOX_NORECURSE && toys.stacktop)
- if (labs((unsigned long)toys.stacktop-(unsigned long)&which)>6000) return;
+ if (labs((long)toys.stacktop-(long)&which)>6000) return;
// Return if we need to re-exec to acquire root via suid bit.
if (toys.which && (which->flags&TOYFLAG_ROOTONLY) && toys.wasroot) return;