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:
William Lallemand 2023-04-13 14:33:52 +02:00
parent 28f2a590f6
commit 3f210970bf
2 changed files with 11 additions and 8 deletions

View File

@ -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_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);

View File

@ -788,7 +788,7 @@ struct stktable_type stktable_types[SMP_TYPES] = {
* 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 @@ int stktable_parse_type(char **args, int *myidx, unsigned long *type, size_t *ke
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 @@ int stktable_parse_type(char **args, int *myidx, unsigned long *type, size_t *ke
}
return 0;
}
ha_alert("parsing [%s:%d] : %s: unknown type '%s'.\n", file, linenum, args[0], args[*myidx]);
return 1;
}
@ -975,9 +980,7 @@ int parse_stick_table(const char *file, int linenum, char **args,
}
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;
}