BUG/MINOR: stick_table: alert when type len has incorrect characters
Alert when the len argument of a stick table type contains incorrect
characters.
Replace atol by strtol.
Could be backported in every maintained versions.
(cherry picked from commit 3f210970bf9450156005e28ee45f64f6d39bc936)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit ecbb9244a03e5865bac8e0b9dac9a7e8f8b4c360)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 7b31ac83489355021d1e07ed1a27625798cb9bc5)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit f70fd555010d4abe8a3154bcbd3f425ebf6956ce)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
diff --git a/include/haproxy/stick_table.h b/include/haproxy/stick_table.h
index c9fb85e..5fd8d1e 100644
--- a/include/haproxy/stick_table.h
+++ b/include/haproxy/stick_table.h
@@ -46,7 +46,7 @@
int stksess_kill(struct stktable *t, struct stksess *ts, int decrefcount);
int stktable_init(struct stktable *t);
-int stktable_parse_type(char **args, int *idx, unsigned long *type, size_t *key_size);
+int stktable_parse_type(char **args, int *idx, unsigned long *type, size_t *key_size, const char *file, int linenum);
int parse_stick_table(const char *file, int linenum, char **args,
struct stktable *t, char *id, char *nid, struct peers *peers);
struct stksess *stktable_get_entry(struct stktable *table, struct stktable_key *key);
diff --git a/src/stick_table.c b/src/stick_table.c
index 67f2129..851ae10 100644
--- a/src/stick_table.c
+++ b/src/stick_table.c
@@ -691,7 +691,7 @@
* Returns 0 on successful parsing, else 1.
* <myidx> is set at next configuration <args> index.
*/
-int stktable_parse_type(char **args, int *myidx, unsigned long *type, size_t *key_size)
+int stktable_parse_type(char **args, int *myidx, unsigned long *type, size_t *key_size, const char *file, int linenum)
{
for (*type = 0; *type < SMP_TYPES; (*type)++) {
if (!stktable_types[*type].kw)
@@ -704,10 +704,14 @@
if (stktable_types[*type].flags & STK_F_CUSTOM_KEYSIZE) {
if (strcmp("len", args[*myidx]) == 0) {
+ char *stop;
+
(*myidx)++;
- *key_size = atol(args[*myidx]);
- if (!*key_size)
- break;
+ *key_size = strtol(args[*myidx], &stop, 10);
+ if (*stop != '\0' || !*key_size) {
+ ha_alert("parsing [%s:%d] : 'len' expects a positive integer argument.\n", file, linenum);
+ return 1;
+ }
if (*type == SMP_T_STR) {
/* null terminated string needs +1 for '\0'. */
(*key_size)++;
@@ -717,6 +721,7 @@
}
return 0;
}
+ ha_alert("parsing [%s:%d] : %s: unknown type '%s'.\n", file, linenum, args[0], args[*myidx]);
return 1;
}
@@ -862,9 +867,7 @@
}
else if (strcmp(args[idx], "type") == 0) {
idx++;
- if (stktable_parse_type(args, &idx, &t->type, &t->key_size) != 0) {
- ha_alert("parsing [%s:%d] : %s: unknown type '%s'.\n",
- file, linenum, args[0], args[idx]);
+ if (stktable_parse_type(args, &idx, &t->type, &t->key_size, file, linenum) != 0) {
err_code |= ERR_ALERT | ERR_FATAL;
goto out;
}