Browse code

dispatcher: check weight value to be in expected range

(cherry picked from commit e00f610203fee957a22afc5f8103c1482a925138)

Daniel-Constantin Mierla authored on 10/12/2020 15:34:28 • Henning Westerholt committed on 21/12/2020 15:27:07
Showing 1 changed files
... ...
@@ -281,7 +281,7 @@ int ds_set_attrs(ds_dest_t *dest, str *vattrs)
281 281
 	param_hooks_t phooks;
282 282
 	param_t *pit = NULL;
283 283
 	str param;
284
-	int tmp_rweight = 0;
284
+	int tmp_ival = 0;
285 285
 	str sattrs;
286 286
 
287 287
 	if(vattrs == NULL || vattrs->len <= 0) {
... ...
@@ -316,7 +316,15 @@ int ds_set_attrs(ds_dest_t *dest, str *vattrs)
316 316
 			str2sint(&pit->body, &dest->attrs.congestion_control);
317 317
 		} else if(pit->name.len == 6
318 318
 				  && strncasecmp(pit->name.s, "weight", 6) == 0) {
319
-			str2sint(&pit->body, &dest->attrs.weight);
319
+			tmp_ival = 0;
320
+			str2sint(&pit->body, &tmp_ival);
321
+			if(tmp_ival >= 1 && tmp_ival <= 100) {
322
+				dest->attrs.weight = tmp_ival;
323
+			} else {
324
+				dest->attrs.weight = 0;
325
+				LM_ERR("weight %d not in 1-100 range - ignoring destination",
326
+						tmp_ival);
327
+			}
320 328
 		} else if(pit->name.len == 7
321 329
 				  && strncasecmp(pit->name.s, "maxload", 7) == 0) {
322 330
 			str2sint(&pit->body, &dest->attrs.maxload);
... ...
@@ -325,12 +333,13 @@ int ds_set_attrs(ds_dest_t *dest, str *vattrs)
325 333
 			dest->attrs.socket = pit->body;
326 334
 		} else if(pit->name.len == 7
327 335
 				  && strncasecmp(pit->name.s, "rweight", 7) == 0) {
328
-			tmp_rweight = 0;
329
-			str2sint(&pit->body, &tmp_rweight);
330
-			if(tmp_rweight >= 1 && tmp_rweight <= 100) {
331
-				dest->attrs.rweight = tmp_rweight;
336
+			tmp_ival = 0;
337
+			str2sint(&pit->body, &tmp_ival);
338
+			if(tmp_ival >= 1 && tmp_ival <= 100) {
339
+				dest->attrs.rweight = tmp_ival;
332 340
 			} else {
333
-				LM_ERR("rweight %d not in 1-100 range; skipped", tmp_rweight);
341
+				dest->attrs.rweight = 0;
342
+				LM_WARN("rweight %d not in 1-100 range - ignoring", tmp_ival);
334 343
 			}
335 344
 		} else if(pit->name.len == 9
336 345
 				&& strncasecmp(pit->name.s, "ping_from", 9) == 0) {