From: Willy Tarreau Date: Sun, 20 Jun 2010 08:41:54 +0000 (+0200) Subject: [MEDIUM] stick-tables: add stored data argument type checking X-Git-Tag: v1.5-dev8~515 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ac78288eaf9601351731b187dfc006648546d3b8;p=thirdparty%2Fhaproxy.git [MEDIUM] stick-tables: add stored data argument type checking We're now able to return errors based on the validity of an argument passed to a stick-table store data type. We also support ARG_T_DELAY to pass delays to stored data types (eg: for rate counters). --- diff --git a/include/proto/stick_table.h b/include/proto/stick_table.h index 7381737c0a..7cfeaae234 100644 --- a/include/proto/stick_table.h +++ b/include/proto/stick_table.h @@ -53,6 +53,8 @@ struct proxy *find_stktable(const char *name); * not NULL. Returns PE_NONE (0) if OK or an error code among : * - PE_ENUM_OOR if does not exist * - PE_EXIST if is already registered + * - PE_ARG_NOT_USE if was provided but not expected + * - PE_ARG_MISSING if was expected but not provided */ static inline int stktable_alloc_data_type(struct stktable *t, int type, const char *sa) { @@ -63,12 +65,27 @@ static inline int stktable_alloc_data_type(struct stktable *t, int type, const c /* already allocated */ return PE_EXIST; + switch (stktable_data_types[type].arg_type) { + case ARG_T_NONE: + if (sa) + return PE_ARG_NOT_USED; + break; + case ARG_T_INT: + if (!sa) + return PE_ARG_MISSING; + t->data_arg[type].i = atoi(sa); + break; + case ARG_T_DELAY: + if (!sa) + return PE_ARG_MISSING; + sa = parse_time_err(sa, &t->data_arg[type].u, TIME_UNIT_MS); + if (sa) + return PE_ARG_INVC; /* invalid char */ + break; + } + t->data_size += stktable_data_types[type].data_length; t->data_ofs[type] = -t->data_size; - /* right now only int type is supported, but we may later support type- - * specific arg type. - */ - t->data_arg[type].i = sa ? atoi(sa) : 0; return PE_NONE; } diff --git a/src/cfgparse.c b/src/cfgparse.c index 3fa6c7eb1b..7a33910190 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -2275,7 +2275,7 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm) /* myidx already points to next arg */ } else if (strcmp(args[myidx], "store") == 0) { - int type; + int type, err; char *cw, *nw, *sa; myidx++; @@ -2310,10 +2310,33 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm) err_code |= ERR_ALERT | ERR_FATAL; goto out; } - if (stktable_alloc_data_type(&curproxy->table, type, sa)) { + + err = stktable_alloc_data_type(&curproxy->table, type, sa); + switch (err) { + case PE_NONE: break; + case PE_EXIST: Warning("parsing [%s:%d]: %s: store option '%s' already enabled, ignored.\n", file, linenum, args[0], cw); err_code |= ERR_WARN; + break; + + case PE_ARG_MISSING: + Alert("parsing [%s:%d] : %s: missing argument to store option '%s'.\n", + file, linenum, args[0], cw); + err_code |= ERR_ALERT | ERR_FATAL; + goto out; + + case PE_ARG_NOT_USED: + Alert("parsing [%s:%d] : %s: unexpected argument to store option '%s'.\n", + file, linenum, args[0], cw); + err_code |= ERR_ALERT | ERR_FATAL; + goto out; + + default: + Alert("parsing [%s:%d] : %s: error when processing store option '%s'.\n", + file, linenum, args[0], cw); + err_code |= ERR_ALERT | ERR_FATAL; + goto out; } } myidx++;