Quantcast
Channel: Serverphorums.com - HAProxy
Viewing all articles
Browse latest Browse all 5112

Argument parsing and empty argument list (no replies)

$
0
0
Hey!

The documentation of req.hdr() says that "name" is optional. However, no
match can bound without specifying the name. In `smp_fetch_hdr()`, we
have:

#v+
if (args) {
if (args[0].type != ARGT_STR)
return 0;
name_str = args[0].data.str.str;
name_len = args[0].data.str.len;

if (args[1].type == ARGT_SINT)
occ = args[1].data.sint;
}
#v-

When empty, `args == empty_arg_list` and `args->type == 0`. So, the
check could be changed to `args && args == empty_arg_list` (no other
occurence in the code) or to `args && args[0].type == ARGT_STR`.

For req.fhdr(), documentation sthats that name is not optional but the
code is similar and it shouldn't be different from req.hdr(). For
req.fhdr_cnt(), the name is optional and the code is correct in this
respect:

#v+
if (args && args->type == ARGT_STR) {
name = args->data.str.str;
len = args->data.str.len;
}
#v-

Also, there are a lot of `if (args)`, while it seems that `args` is
guaranteed to be non-NULL. So, those occurrences should be replaced by
`if (args != empty_arg_list)`, right?

No patch proposed yet, since I am unsure of the right direction.
--
Make your program read from top to bottom.
- The Elements of Programming Style (Kernighan & Plauger)

Viewing all articles
Browse latest Browse all 5112

Trending Articles