From 20b969d26b5953bfe0457aa1225cb1af09c25bbd Mon Sep 17 00:00:00 2001 From: Sebastian Weyer <50481737+DocSepp@users.noreply.github.com> Date: Fri, 16 Feb 2024 19:06:40 +0100 Subject: [PATCH] ao.c: set proper bounds for Analog_Output_Present_Value_Set and Analog_Output_Present_Value_Write (#575) * ao.c: set proper bounds for Analog_Output_Present_Value_Write The lower and upper bounds to the value passed to this function were hard-coded to 0 and 100 respectively. This meant that a client was not able to write a value outside of these bounds, regardless of the values of `Min_Pres_Value` and `Max_Pres_Value`. Now properly compare the new value against `Min_Pres_Value` and `Max_Pres_Value` and only return `ERROR_CODE_VALUE_OUT_OF_RANGE` when it is outside of this range. Signed-off-by: Sebastian Weyer * ao.c: make Analog_Output_Present_Value_Set return 0 when out of range Compare the new value passsed to `Analog_Output_Present_Value_Set` against `Min_Pres_Value` and `Max_Pres_Value`. If the new value is outside of these bounds, don't update the present value and return false. Signed-off-by: Sebastian Weyer --------- Signed-off-by: Sebastian Weyer Co-authored-by: Sebastian Weyer --- src/bacnet/basic/object/ao.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/bacnet/basic/object/ao.c b/src/bacnet/basic/object/ao.c index fa2e3713..f66863ba 100644 --- a/src/bacnet/basic/object/ao.c +++ b/src/bacnet/basic/object/ao.c @@ -340,7 +340,8 @@ bool Analog_Output_Present_Value_Set( pObject = Keylist_Data(Object_List, object_instance); if (pObject) { - if ((priority >= 1) && (priority <= BACNET_MAX_PRIORITY)) { + if ((priority >= 1) && (priority <= BACNET_MAX_PRIORITY) && + value >= pObject->Min_Pres_Value && value <= pObject->Max_Pres_Value) { pObject->Relinquished[priority - 1] = false; pObject->Priority_Array[priority - 1] = value; Analog_Output_Present_Value_COV_Detect( @@ -402,7 +403,7 @@ static bool Analog_Output_Present_Value_Write(uint32_t object_instance, pObject = Keylist_Data(Object_List, object_instance); if (pObject) { if ((priority >= 1) && (priority <= BACNET_MAX_PRIORITY) && - (value >= 0.0) && (value <= 100.0)) { + (value >= pObject->Min_Pres_Value) && (value <= pObject->Max_Pres_Value)) { if (priority != 6) { old_value = Analog_Output_Present_Value(object_instance); Analog_Output_Present_Value_Set(