mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-22 06:11:32 +02:00
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.
This commit is contained in:
parent
28f2a590f6
commit
3f210970bf
@ -47,7 +47,7 @@ int stksess_kill(struct stktable *t, struct stksess *ts, int decrefcount);
|
|||||||
int stktable_get_key_shard(struct stktable *t, const void *key, size_t len);
|
int stktable_get_key_shard(struct stktable *t, const void *key, size_t len);
|
||||||
|
|
||||||
int stktable_init(struct stktable *t);
|
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,
|
int parse_stick_table(const char *file, int linenum, char **args,
|
||||||
struct stktable *t, char *id, char *nid, struct peers *peers);
|
struct stktable *t, char *id, char *nid, struct peers *peers);
|
||||||
struct stksess *stktable_get_entry(struct stktable *table, struct stktable_key *key);
|
struct stksess *stktable_get_entry(struct stktable *table, struct stktable_key *key);
|
||||||
|
@ -788,7 +788,7 @@ struct stktable_type stktable_types[SMP_TYPES] = {
|
|||||||
* Returns 0 on successful parsing, else 1.
|
* Returns 0 on successful parsing, else 1.
|
||||||
* <myidx> is set at next configuration <args> index.
|
* <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)++) {
|
for (*type = 0; *type < SMP_TYPES; (*type)++) {
|
||||||
if (!stktable_types[*type].kw)
|
if (!stktable_types[*type].kw)
|
||||||
@ -801,10 +801,14 @@ int stktable_parse_type(char **args, int *myidx, unsigned long *type, size_t *ke
|
|||||||
|
|
||||||
if (stktable_types[*type].flags & STK_F_CUSTOM_KEYSIZE) {
|
if (stktable_types[*type].flags & STK_F_CUSTOM_KEYSIZE) {
|
||||||
if (strcmp("len", args[*myidx]) == 0) {
|
if (strcmp("len", args[*myidx]) == 0) {
|
||||||
|
char *stop;
|
||||||
|
|
||||||
(*myidx)++;
|
(*myidx)++;
|
||||||
*key_size = atol(args[*myidx]);
|
*key_size = strtol(args[*myidx], &stop, 10);
|
||||||
if (!*key_size)
|
if (*stop != '\0' || !*key_size) {
|
||||||
break;
|
ha_alert("parsing [%s:%d] : 'len' expects a positive integer argument.\n", file, linenum);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
if (*type == SMP_T_STR) {
|
if (*type == SMP_T_STR) {
|
||||||
/* null terminated string needs +1 for '\0'. */
|
/* null terminated string needs +1 for '\0'. */
|
||||||
(*key_size)++;
|
(*key_size)++;
|
||||||
@ -814,6 +818,7 @@ int stktable_parse_type(char **args, int *myidx, unsigned long *type, size_t *ke
|
|||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
ha_alert("parsing [%s:%d] : %s: unknown type '%s'.\n", file, linenum, args[0], args[*myidx]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -975,9 +980,7 @@ int parse_stick_table(const char *file, int linenum, char **args,
|
|||||||
}
|
}
|
||||||
else if (strcmp(args[idx], "type") == 0) {
|
else if (strcmp(args[idx], "type") == 0) {
|
||||||
idx++;
|
idx++;
|
||||||
if (stktable_parse_type(args, &idx, &t->type, &t->key_size) != 0) {
|
if (stktable_parse_type(args, &idx, &t->type, &t->key_size, file, linenum) != 0) {
|
||||||
ha_alert("parsing [%s:%d] : %s: unknown type '%s'.\n",
|
|
||||||
file, linenum, args[0], args[idx]);
|
|
||||||
err_code |= ERR_ALERT | ERR_FATAL;
|
err_code |= ERR_ALERT | ERR_FATAL;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user