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.
diff --git a/include/haproxy/stick_table.h b/include/haproxy/stick_table.h
index cbec137..90ab6f3 100644
--- a/include/haproxy/stick_table.h
+++ b/include/haproxy/stick_table.h
@@ -47,7 +47,7 @@
int stktable_get_key_shard(struct stktable *t, const void *key, size_t len);
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 7ff4c47..1f46795 100644
--- a/src/stick_table.c
+++ b/src/stick_table.c
@@ -788,7 +788,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)
@@ -801,10 +801,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)++;
@@ -814,6 +818,7 @@
}
return 0;
}
+ ha_alert("parsing [%s:%d] : %s: unknown type '%s'.\n", file, linenum, args[0], args[*myidx]);
return 1;
}
@@ -975,9 +980,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;
}