sml_parser
sml_parser copied to clipboard
Possible infinite loop in smlOBISByUnit()
I have a setup where I do get quite a loot of checksum errors when reading my smart meter. The sml_parser library is also implemented in a way so that data is parsed on-the-fly, so before any checksum could have been checked.
I encountered once that my program was hanging. When attaching with the debugger it was in an infinite loop in smlOBISByUnit() function. Sadly, I did not do any further investigation. So I do not know what input data has caused this infinite loop.
When having a look at the implementation of smlOBISByUnit() I am wondering, if continuing the loop if "pos" is greater 6 makes any sense? So I updated my copy of sml_parser with the below patch which will make sure, it cannot get stuck in an endless loop anymore.
Any comments on it? All tests still pass.
diff --git a/sml.cpp b/sml.cpp
index 0edee97..c357653 100644
--- a/sml.cpp
+++ b/sml.cpp
@@ -367,6 +367,7 @@ void smlOBISByUnit(long long int &val, signed char &scaler, sml_units_t unit)
// left shift received bytes to 64 bit signed integer
val = (val << 8) | listBuffer[i + y];
}
+ return;
}
i += size;
}