summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Engelhardt <jengelh@medozas.de>2010-11-02 09:10:34 +0100
committerJan Engelhardt <jengelh@medozas.de>2010-11-02 09:17:09 +0100
commit648fd1ad68ae2ec675ac07efee80783912535404 (patch)
tree4e4590c9449f9f3c272f1a8d18216b64f7d99b66
parent600f38db82548a683775fd89b6e136673e924097 (diff)
libxt_TOS: avoid an undesired overflowing computation
The @bits parameter was wrongly labeled and should have been @max already. This makes the - overflowing - 1<<bits redundant of course. Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
-rw-r--r--extensions/tos_values.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/extensions/tos_values.c b/extensions/tos_values.c
index 10add198..a65ef25d 100644
--- a/extensions/tos_values.c
+++ b/extensions/tos_values.c
@@ -26,15 +26,13 @@ static const struct tos_symbol_info {
/*
* tos_parse_numeric - parse sth. like "15/255"
*
- * @s: input string
- * @info: accompanying structure
- * @bits: number of bits that are allowed
- * (8 for IPv4 TOS field, 4 for IPv6 Priority Field)
+ * @str: input string
+ * @tvm: (value/mask) tuple
+ * @max: maximum allowed value (must be pow(2,some_int)-1)
*/
static bool tos_parse_numeric(const char *str, struct tos_value_mask *tvm,
- unsigned int bits)
+ unsigned int max)
{
- const unsigned int max = (1 << bits) - 1;
unsigned int value;
char *end;
@@ -56,17 +54,22 @@ static bool tos_parse_numeric(const char *str, struct tos_value_mask *tvm,
return true;
}
+/**
+ * @str: input string
+ * @tvm: (value/mask) tuple
+ * @def_mask: mask to force when a symbolic name is used
+ */
static bool tos_parse_symbolic(const char *str, struct tos_value_mask *tvm,
unsigned int def_mask)
{
- const unsigned int max = UINT8_MAX;
+ static const unsigned int max = UINT8_MAX;
const struct tos_symbol_info *symbol;
char *tmp;
if (xtables_strtoui(str, &tmp, NULL, 0, max))
return tos_parse_numeric(str, tvm, max);
- /* Do not consider ECN bits */
+ /* Do not consider ECN bits when using preset names */
tvm->mask = def_mask;
for (symbol = tos_symbol_names; symbol->name != NULL; ++symbol)
if (strcasecmp(str, symbol->name) == 0) {