Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[JENKINS-26729] Fixed infinite loop.
In some situations where an environment variable resolves to itself it
the plugin could get stuck in an infinite loop.
This is fixed now, because the plugin now checks for such situations and
then does not resolve such bad envionrment variables.
  • Loading branch information
Bagira80 committed Oct 11, 2016
1 parent d43389b commit 6fcbe02
Showing 1 changed file with 14 additions and 6 deletions.
Expand Up @@ -167,16 +167,24 @@ public static String formatVersionNumber(String versionNumberFormatString,
int yearsSinceStart = buildDate.get(Calendar.YEAR) - projectStartCal.get(Calendar.YEAR);
replaceValue = sizeTo(Integer.toString(yearsSinceStart), argumentString.length());
}
// if it's not one of the defined values, check the environment variables
// NOTE: Actually, we should never get here, because environment-variables
// should already be resolved at the beginning of this method.
// if it's not one of the defined values, check the environment variables (again)
// NOTE: This probably means, that an environment-variable resolves to itself, which
// might result in an infinite loop. Check for this!
else {
LOGGER.fine("It seems we are missing some implementation. We should actually never get here! " +
"[expressionKey == " + expressionKey + "]");
LOGGER.fine("Special case: A variable could not be resolved. (Does it resolve to itself?)" +
" [var == " + expressionKey + "]");
if (enVars != null) {
for (Map.Entry entry : enVars.entrySet()) {
if (entry.getKey().equals(expressionKey)) {
replaceValue = (String)entry.getValue();
// Check for variable which resolves to itself!
if (entry.getValue().equals("${" + expressionKey + "}")) {
LOGGER.fine("Yes, the variable resolves to itself. Ignoring it." +
" [var == " + expressionKey + "]");
} else {
LOGGER.fine("No, the variable does not resolve to itself. Using it." +
" [var == " + expressionKey + "]");
replaceValue = (String)entry.getValue();
}
}
}
}
Expand Down

0 comments on commit 6fcbe02

Please sign in to comment.