Skip to content

Commit 2babb94

Browse files
committed
Expect an error when processing a directive within a cfg section. (#538) (#539)
1 parent 077d8a1 commit 2babb94

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

tempesta_fw/cfg.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,12 @@ entry_reset(TfwCfgEntry *e)
211211
static int
212212
entry_set_name(TfwCfgEntry *e, const char *name_src, size_t name_len)
213213
{
214-
BUG_ON(!e || !name_src || !name_len);
214+
BUG_ON(!e);
215215
BUG_ON(e->name);
216216

217+
if (!name_src || !name_len)
218+
return -EINVAL;
219+
217220
if (!check_identifier(name_src, name_len))
218221
return -EINVAL;
219222

@@ -229,7 +232,11 @@ entry_add_val(TfwCfgEntry *e, const char *val_src, size_t val_len)
229232
{
230233
const char *val;
231234

232-
BUG_ON(!e || !val_src || e->val_n > ARRAY_SIZE(e->vals));
235+
BUG_ON(!e);
236+
BUG_ON(e->val_n > ARRAY_SIZE(e->vals));
237+
238+
if (!val_src || !val_len)
239+
return -EINVAL;
233240

234241
if (e->val_n == ARRAY_SIZE(e->vals)) {
235242
TFW_ERR("maximum number of values per entry reached\n");
@@ -250,12 +257,14 @@ entry_add_attr(TfwCfgEntry *e, const char *key_src, size_t key_len,
250257
{
251258
const char *key, *val;
252259

253-
BUG_ON(!e || !key_src || !val_src);
254-
BUG_ON(!key_len); /* Although empty values are allowed. */
260+
BUG_ON(!e);
255261
BUG_ON(e->attr_n > ARRAY_SIZE(e->attrs));
256262

263+
if (!key_src || !key_len || !val_src || !val_len)
264+
return -EINVAL;
265+
257266
if (e->attr_n == ARRAY_SIZE(e->attrs)) {
258-
TFW_ERR("maximum numer of attributes per entry reached\n");
267+
TFW_ERR("maximum number of attributes per entry reached\n");
259268
return -ENOBUFS;
260269
}
261270

@@ -623,6 +632,9 @@ parse_cfg_entry(TfwCfgParserState *ps)
623632
PFSM_COND_MOVE(ps->t == TOKEN_LITERAL, PS_MAYBE_EQSIGN);
624633
FSM_COND_JMP(ps->t == TOKEN_SEMICOLON, PS_SEMICOLON);
625634
FSM_COND_JMP(ps->t == TOKEN_LBRACE, PS_LBRACE);
635+
636+
ps->err = -EINVAL;
637+
FSM_JMP(PS_EXIT);
626638
}
627639

628640
FSM_STATE(PS_MAYBE_EQSIGN) {

0 commit comments

Comments
 (0)