Browse code

- check the integer range even if a fixup function is defined - min and max values can be the same

Miklos Tirpak authored on 31/01/2008 16:16:54
Showing 1 changed files
... ...
@@ -280,6 +280,16 @@ int cfg_set_now(cfg_ctx_t *ctx, str *group_name, str *var_name,
280 280
 	if (convert_val(val_type, val, CFG_INPUT_TYPE(var), &v))
281 281
 		goto error0;
282 282
 	
283
+	if ((CFG_INPUT_TYPE(var) == CFG_INPUT_INT) 
284
+	&& (var->def->min || var->def->max)) {
285
+		/* perform a simple min-max check for integers */
286
+		if (((int)(long)v < var->def->min)
287
+		|| ((int)(long)v > var->def->max)) {
288
+			LOG(L_ERR, "ERROR: cfg_set_now(): integer value is out of range\n");
289
+			goto error0;
290
+		}
291
+	}
292
+
283 293
 	if (var->def->on_change_cb) {
284 294
 		/* Call the fixup function.
285 295
 		There is no need to set a temporary cfg handle,
... ...
@@ -291,14 +301,6 @@ int cfg_set_now(cfg_ctx_t *ctx, str *group_name, str *var_name,
291 301
 			goto error0;
292 302
 		}
293 303
 
294
-	} else if ((CFG_VAR_TYPE(var) == CFG_VAR_INT) 
295
-	&& (var->def->min != var->def->max)) {
296
-		/* perform a simple min-max check for integers */
297
-		if (((int)(long)v < var->def->min)
298
-		|| ((int)(long)v > var->def->max)) {
299
-			LOG(L_ERR, "ERROR: cfg_set_now(): integer value is out of range\n");
300
-			goto error0;
301
-		}
302 304
 	}
303 305
 
304 306
 	if (cfg_shmized) {
... ...
@@ -500,6 +502,16 @@ int cfg_set_delayed(cfg_ctx_t *ctx, str *group_name, str *var_name,
500 502
 	if (convert_val(val_type, val, CFG_INPUT_TYPE(var), &v))
501 503
 		goto error0;
502 504
 
505
+	if ((CFG_INPUT_TYPE(var) == CFG_INPUT_INT) 
506
+	&& (var->def->min || var->def->max)) {
507
+		/* perform a simple min-max check for integers */
508
+		if (((int)(long)v < var->def->min)
509
+		|| ((int)(long)v > var->def->max)) {
510
+			LOG(L_ERR, "ERROR: cfg_set_delayed(): integer value is out of range\n");
511
+			goto error;
512
+		}
513
+	}
514
+
503 515
 	/* the ctx must be locked while reading and writing
504 516
 	the list of changed variables */
505 517
 	CFG_CTX_LOCK(ctx);
... ...
@@ -548,14 +560,6 @@ int cfg_set_delayed(cfg_ctx_t *ctx, str *group_name, str *var_name,
548 560
 		}
549 561
 		if (temp_handle_created) pkg_free(temp_handle);
550 562
 
551
-	} else if ((CFG_VAR_TYPE(var) == CFG_VAR_INT) 
552
-	&& (var->def->min != var->def->max)) {
553
-		/* perform a simple min-max check for integers */
554
-		if (((int)(long)v < var->def->min)
555
-		|| ((int)(long)v > var->def->max)) {
556
-			LOG(L_ERR, "ERROR: cfg_set_delayed(): integer value is out of range\n");
557
-			goto error;
558
-		}
559 563
 	}
560 564
 
561 565
 	/* everything went ok, we can add the new value to the list */