From 26c0bb082ca1c03aa4eb788385d4fecf7cc46a6b Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Sun, 5 Dec 2021 15:48:18 -0500 Subject: eval: Check that RLIM_SAVED_{CUR,MAX} are defined before using them Apparently they're missing on Debian kfreebsd: https://buildd.debian.org/status/fetch.php?pkg=bfs&arch=kfreebsd-amd64&ver=2.3-1&stamp=1638379495&raw=0 --- eval.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to 'eval.c') diff --git a/eval.c b/eval.c index b35a236..ec2701b 100644 --- a/eval.c +++ b/eval.c @@ -1416,11 +1416,32 @@ done: return state.action; } +/** Check if an rlimit value is infinite. */ +static bool rlim_isinf(rlim_t r) { + // Consider RLIM_{INFINITY,SAVED_{CUR,MAX}} all equally infinite + if (r == RLIM_INFINITY) { + return true; + } + +#ifdef RLIM_SAVED_CUR + if (r == RLIM_SAVED_CUR) { + return true; + } +#endif + +#ifdef RLIM_SAVED_MAX + if (r == RLIM_SAVED_MAX) { + return true; + } +#endif + + return false; +} + /** Compare two rlimit values, accounting for RLIM_INFINITY etc. */ static int rlim_cmp(rlim_t a, rlim_t b) { - // Consider RLIM_{INFINITY,SAVED_{CUR,MAX}} all equally infinite - bool a_inf = a == RLIM_INFINITY || a == RLIM_SAVED_CUR || a == RLIM_SAVED_MAX; - bool b_inf = b == RLIM_INFINITY || b == RLIM_SAVED_CUR || b == RLIM_SAVED_MAX; + bool a_inf = rlim_isinf(a); + bool b_inf = rlim_isinf(b); if (a_inf || b_inf) { return a_inf - b_inf; } -- cgit v1.2.3