[Bf-blender-cvs] [bb4a12914fa] master: Add some security checks against future bad float UIprecision values.

Bastien Montagne noreply at git.blender.org
Mon Sep 18 20:04:43 CEST 2017


Commit: bb4a12914fad3cb1867e34ff01a5ddc9f761e7f0
Author: Bastien Montagne
Date:   Mon Sep 18 19:50:40 2017 +0200
Branches: master
https://developer.blender.org/rBbb4a12914fad3cb1867e34ff01a5ddc9f761e7f0

Add some security checks against future bad float UIprecision values.

This commit and previous one should be backported to 2.79a should we
release it.

===================================================================

M	source/blender/editors/include/UI_interface.h
M	source/blender/editors/interface/interface.c
M	source/blender/makesrna/intern/rna_define.c

===================================================================

diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index 9376de8c095..e14a3a3ff0a 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -996,7 +996,7 @@ void uiItemsFullEnumO(
         struct IDProperty *properties, int context, int flag);
 void uiItemsFullEnumO_items(
         uiLayout *layout, struct wmOperatorType *ot, PointerRNA ptr, PropertyRNA *prop,
-        IDProperty *properties, int context, int flag,
+        struct IDProperty *properties, int context, int flag,
         const EnumPropertyItem *item_array, int totitem);
 
 void uiItemL(uiLayout *layout, const char *name, int icon); /* label */
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index fd5159bb76c..5c05fc8c530 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -488,6 +488,9 @@ static int ui_but_calc_float_precision(uiBut *but, double value)
 	else if (prec == -1) {
 		prec = (but->hardmax < 10.001f) ? 3 : 2;
 	}
+	else {
+		CLAMP(prec, 0, UI_PRECISION_FLOAT_MAX);
+	}
 
 	return UI_calc_float_precision(prec, value);
 }
diff --git a/source/blender/makesrna/intern/rna_define.c b/source/blender/makesrna/intern/rna_define.c
index 0e91c158669..118dd0b15de 100644
--- a/source/blender/makesrna/intern/rna_define.c
+++ b/source/blender/makesrna/intern/rna_define.c
@@ -44,6 +44,8 @@
 
 #include "BLT_translation.h"
 
+#include "UI_interface.h"  /* For things like UI_PRECISION_FLOAT_MAX... */
+
 #include "RNA_define.h"
 
 #include "rna_internal.h"
@@ -1405,13 +1407,13 @@ void RNA_def_property_ui_icon(PropertyRNA *prop, int icon, bool consecutive)
  * For ints, whole values are used.
  *
  * \param precision The number of zeros to show
- * (as a whole number - common range is 1 - 6), see PRECISION_FLOAT_MAX
+ * (as a whole number - common range is 1 - 6), see UI_PRECISION_FLOAT_MAX
  */
 void RNA_def_property_ui_range(PropertyRNA *prop, double min, double max, double step, int precision)
 {
 	StructRNA *srna = DefRNA.laststruct;
 
-#ifdef DEBUG
+#ifndef NDEBUG
 	if (min > max) {
 		fprintf(stderr, "%s: \"%s.%s\", min > max.\n",
 		        __func__, srna->identifier, prop->identifier);
@@ -1424,8 +1426,8 @@ void RNA_def_property_ui_range(PropertyRNA *prop, double min, double max, double
 		DefRNA.error = 1;
 	}
 
-	if (precision < -1 || precision > 10) {
-		fprintf(stderr, "%s: \"%s.%s\", step outside range.\n",
+	if (precision < -1 || precision > UI_PRECISION_FLOAT_MAX) {
+		fprintf(stderr, "%s: \"%s.%s\", precision outside range.\n",
 		        __func__, srna->identifier, prop->identifier);
 		DefRNA.error = 1;
 	}
@@ -1447,21 +1449,6 @@ void RNA_def_property_ui_range(PropertyRNA *prop, double min, double max, double
 			fprop->softmax = (float)max;
 			fprop->step = (float)step;
 			fprop->precision = (int)precision;
-#if 0 /* handy but annoying */
-			if (DefRNA.preprocess) {
-				/* check we're not over PRECISION_FLOAT_MAX */
-				if (fprop->precision > 6) {
-					fprintf(stderr, "%s: \"%s.%s\", precision value over maximum.\n",
-					        __func__, srna->identifier, prop->identifier);
-					DefRNA.error = 1;
-				}
-				else if (fprop->precision < 1) {
-					fprintf(stderr, "%s: \"%s.%s\", precision value under minimum.\n",
-					        __func__, srna->identifier, prop->identifier);
-					DefRNA.error = 1;
-				}
-			}
-#endif
 			break;
 		}
 		default:



More information about the Bf-blender-cvs mailing list