Skip to content

Commit d41273c

Browse files
committed
MINOR: cfgparse-quic: strengthen quic-cc-algo parsing
quic-cc-algo is a bind keyword which is used to specify the congestion control algorithm. It is parsed via function bind_parse_quic_cc_algo(). The parsing function was too laxed as it used strncmp for algo token matching. This could cause surprise if specifying an invalid algorithm but starting identically to another entry. Especially if extra parameters are specified in parenthesis, as in this case parameters value will be completely ignored and default value used instead. To fix this, convert algo argument to ist. Then, use istsplit() to extract algo token from the optional extra arguments and compare the whole value with isteq().
1 parent 3500865 commit d41273c

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/cfgparse-quic.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ static int bind_parse_quic_cc_algo(char **args, int cur_arg, struct proxy *px,
102102
{
103103
struct quic_cc_algo *cc_algo = NULL;
104104
const char *algo = NULL;
105+
struct ist algo_ist, arg_ist;
105106
char *arg;
106107

107108
cc_algo = calloc(1, sizeof(struct quic_cc_algo));
@@ -116,19 +117,21 @@ static int bind_parse_quic_cc_algo(char **args, int cur_arg, struct proxy *px,
116117
}
117118

118119
arg = args[cur_arg + 1];
119-
if (strncmp(arg, QUIC_CC_NEWRENO_STR, strlen(QUIC_CC_NEWRENO_STR)) == 0) {
120+
arg_ist = ist(args[cur_arg + 1]);
121+
algo_ist = istsplit(&arg_ist, '(');
122+
if (isteq(algo_ist, ist(QUIC_CC_NEWRENO_STR))) {
120123
/* newreno */
121124
algo = QUIC_CC_NEWRENO_STR;
122125
*cc_algo = quic_cc_algo_nr;
123126
arg += strlen(QUIC_CC_NEWRENO_STR);
124127
}
125-
else if (strncmp(arg, QUIC_CC_CUBIC_STR, strlen(QUIC_CC_CUBIC_STR)) == 0) {
128+
else if (isteq(algo_ist, ist(QUIC_CC_CUBIC_STR))) {
126129
/* cubic */
127130
algo = QUIC_CC_CUBIC_STR;
128131
*cc_algo = quic_cc_algo_cubic;
129132
arg += strlen(QUIC_CC_CUBIC_STR);
130133
}
131-
else if (strncmp(arg, QUIC_CC_BBR_STR, strlen(QUIC_CC_BBR_STR)) == 0) {
134+
else if (isteq(algo_ist, ist(QUIC_CC_BBR_STR))) {
132135
if (!experimental_directives_allowed) {
133136
ha_alert("'%s' algo is experimental, must be allowed via a global "
134137
"'expose-experimental-directives'\n", arg);
@@ -140,7 +143,7 @@ static int bind_parse_quic_cc_algo(char **args, int cur_arg, struct proxy *px,
140143
*cc_algo = quic_cc_algo_bbr;
141144
arg += strlen(QUIC_CC_BBR_STR);
142145
}
143-
else if (strncmp(arg, QUIC_CC_NO_CC_STR, strlen(QUIC_CC_NO_CC_STR)) == 0) {
146+
else if (isteq(algo_ist, ist(QUIC_CC_NO_CC_STR))) {
144147
/* nocc */
145148
if (!experimental_directives_allowed) {
146149
ha_alert("'%s' algo is experimental, must be allowed via a global "

0 commit comments

Comments
 (0)