From d1a3dcabf2f89233a99a4a9be08f9f407da0b6b4 Mon Sep 17 00:00:00 2001 From: Siddhesh Poyarekar Date: Tue, 16 Mar 2021 18:31:02 +0530 Subject: tunables: Fix comparison of tunable values The simplification of tunable_set interfaces took care of signed/unsigned conversions while setting values, but comparison with bounds ended up being incorrect; comparing TUNABLE_SIZE_T values for example will fail because SIZE_MAX is seen as -1. Add comparison helpers that take tunable types into account and use them to do comparison instead. --- elf/dl-tunables.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'elf/dl-tunables.h') diff --git a/elf/dl-tunables.h b/elf/dl-tunables.h index ba7ae6b..3880e4a 100644 --- a/elf/dl-tunables.h +++ b/elf/dl-tunables.h @@ -115,6 +115,24 @@ rtld_hidden_proto (__tunable_set_val) /* The default value for TUNABLES_FRONTEND. */ # define TUNABLES_FRONTEND_yes TUNABLES_FRONTEND_valstring +static __always_inline bool +tunable_val_lt (tunable_num_t lhs, tunable_num_t rhs, bool unsigned_cmp) +{ + if (unsigned_cmp) + return (uintmax_t) lhs < (uintmax_t) rhs; + else + return lhs < rhs; +} + +static __always_inline bool +tunable_val_gt (tunable_num_t lhs, tunable_num_t rhs, bool unsigned_cmp) +{ + if (unsigned_cmp) + return (uintmax_t) lhs > (uintmax_t) rhs; + else + return lhs > rhs; +} + /* Compare two name strings, bounded by the name hardcoded in glibc. */ static __always_inline bool tunable_is_name (const char *orig, const char *envname) -- cgit v1.1