aboutsummaryrefslogtreecommitdiff
path: root/elf/dl-tunables.c
diff options
context:
space:
mode:
authorSiddhesh Poyarekar <siddhesh@sourceware.org>2021-03-16 18:31:02 +0530
committerSiddhesh Poyarekar <siddhesh@sourceware.org>2021-04-07 14:06:18 +0530
commitd1a3dcabf2f89233a99a4a9be08f9f407da0b6b4 (patch)
tree923c89bfe24a3ab053337bcf3eb36675ee276c68 /elf/dl-tunables.c
parentbf6b6243c9fe6e9727282ed63f774698e730cedd (diff)
downloadglibc-d1a3dcabf2f89233a99a4a9be08f9f407da0b6b4.tar
glibc-d1a3dcabf2f89233a99a4a9be08f9f407da0b6b4.tar.gz
glibc-d1a3dcabf2f89233a99a4a9be08f9f407da0b6b4.tar.bz2
glibc-d1a3dcabf2f89233a99a4a9be08f9f407da0b6b4.zip
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.
Diffstat (limited to 'elf/dl-tunables.c')
-rw-r--r--elf/dl-tunables.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/elf/dl-tunables.c b/elf/dl-tunables.c
index a2be9cde2f..8b751dcf0d 100644
--- a/elf/dl-tunables.c
+++ b/elf/dl-tunables.c
@@ -107,32 +107,35 @@ do_tunable_update_val (tunable_t *cur, const tunable_val_t *valp,
return;
}
+ bool unsigned_cmp = unsigned_tunable_type (cur->type.type_code);
+
val = valp->numval;
min = minp != NULL ? *minp : cur->type.min;
max = maxp != NULL ? *maxp : cur->type.max;
/* We allow only increasingly restrictive bounds. */
- if (min < cur->type.min)
+ if (tunable_val_lt (min, cur->type.min, unsigned_cmp))
min = cur->type.min;
- if (max > cur->type.max)
+ if (tunable_val_gt (max, cur->type.max, unsigned_cmp))
max = cur->type.max;
/* Skip both bounds if they're inconsistent. */
- if (min > max)
+ if (tunable_val_gt (min, max, unsigned_cmp))
{
min = cur->type.min;
max = cur->type.max;
}
- /* Write everything out if the value and the bounds are valid. */
- if (min <= val && val <= max)
- {
- cur->val.numval = val;
- cur->type.min = min;
- cur->type.max = max;
- cur->initialized = true;
- }
+ /* Bail out if the bounds are not valid. */
+ if (tunable_val_lt (val, min, unsigned_cmp)
+ || tunable_val_lt (max, val, unsigned_cmp))
+ return;
+
+ cur->val.numval = val;
+ cur->type.min = min;
+ cur->type.max = max;
+ cur->initialized = true;
}
/* Validate range of the input value and initialize the tunable CUR if it looks