fgerlits commented on a change in pull request #964:
URL: https://github.com/apache/nifi-minifi-cpp/pull/964#discussion_r551970138
##########
File path: libminifi/src/utils/StringUtils.cpp
##########
@@ -95,21 +95,23 @@ bool StringUtils::StringToFloat(std::string input, float
&output, FailurePolicy
}
std::string StringUtils::replaceEnvironmentVariables(std::string&
original_string) {
- int32_t beg_seq = 0;
- int32_t end_seq = 0;
+ size_t beg_seq = 0;
+ size_t end_seq = 0;
std::string source_string = original_string;
do {
beg_seq = source_string.find("${", beg_seq);
+ if (beg_seq == std::string::npos) {
+ break;
+ }
if (beg_seq > 0 && source_string.at(beg_seq - 1) == '\\') {
beg_seq += 2;
continue;
}
- if (beg_seq < 0)
- break;
end_seq = source_string.find("}", beg_seq + 2);
- if (end_seq < 0)
+ if (end_seq == std::string::npos) {
break;
- if (end_seq - (beg_seq + 2) < 0) {
+ }
+ if (end_seq < beg_seq + 2) {
Review comment:
Yes. I think the intention was to check for `<=`, as a `"... ${} ..."`
input causes an infinite loop without this check. I have changed it to `<=`
and added some more unit tests. (Which showed another bug, which I also fixed.)
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]