Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/build
diff options
context:
space:
mode:
authorMarc-Andre Laperle2014-04-29 05:32:08 +0000
committerAndrew Gvozdev2014-05-21 20:40:30 +0000
commit18ff3be8faa192ed91613a59c7a922477118743c (patch)
tree3885fa8f9272d9fcba94de761099e79c6f1244af /build
parent4e6315d5019ae03aba4d6d69c81492ec014d9fa6 (diff)
downloadorg.eclipse.cdt-18ff3be8faa192ed91613a59c7a922477118743c.tar.gz
org.eclipse.cdt-18ff3be8faa192ed91613a59c7a922477118743c.tar.xz
org.eclipse.cdt-18ff3be8faa192ed91613a59c7a922477118743c.zip
Bug 430966 - Prevent StackOverflowError in Makefile editor
Change-Id: I4c9d04290d047f52d56e3f1e5bf874efc55c51cb Signed-off-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com> Reviewed-on: https://git.eclipse.org/r/25707 Tested-by: Hudson CI Reviewed-by: Andrew Gvozdev <angvoz.dev@gmail.com> Tested-by: Andrew Gvozdev <angvoz.dev@gmail.com>
Diffstat (limited to 'build')
-rw-r--r--build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/makefile/AbstractMakefile.java30
1 files changed, 25 insertions, 5 deletions
diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/makefile/AbstractMakefile.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/makefile/AbstractMakefile.java
index 8d85114dfac..d92e673a5a6 100644
--- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/makefile/AbstractMakefile.java
+++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/makefile/AbstractMakefile.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2010 QNX Software Systems and others.
+ * Copyright (c) 2000, 2014 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,11 +7,13 @@
*
* Contributors:
* QNX Software Systems - Initial API and implementation
+ * Marc-Andre Laperle (Ericsson) - Prevent StackOverflowError (Bug 430966)
*******************************************************************************/
package org.eclipse.cdt.make.internal.core.makefile;
import java.net.URI;
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.List;
import org.eclipse.cdt.make.core.makefile.IBuiltinFunction;
@@ -202,6 +204,18 @@ public abstract class AbstractMakefile extends Parent implements IMakefile {
@Override
public String expandString(String line, boolean recursive) {
+ return expandString(line, recursive, new HashSet<String>());
+ }
+
+ /**
+ * @param line
+ * - line to expand
+ * @param expandedMacros
+ * - keep track of expanded macros to prevent infinite recursion.
+ *
+ * @return line after expanding any macros.
+ */
+ private String expandString(String line, boolean recursive, HashSet<String> expandedMacros) {
int len = line.length();
boolean foundDollar = false;
boolean inMacro = false;
@@ -238,8 +252,11 @@ public abstract class AbstractMakefile extends Parent implements IMakefile {
}
if (defs.length > 0) {
String result = defs[0].getValue().toString();
- if (result.indexOf('$') != -1 && recursive) {
- result = expandString(result, recursive);
+ if (result.indexOf('$') != -1 && recursive && !expandedMacros.contains(result)) {
+ String prevResult = result;
+ expandedMacros.add(prevResult);
+ result = expandString(result, recursive, expandedMacros);
+ expandedMacros.remove(prevResult);
}
buffer.append(result);
} else { // Do not expand
@@ -263,8 +280,11 @@ public abstract class AbstractMakefile extends Parent implements IMakefile {
}
if (defs.length > 0) {
String result = defs[0].getValue().toString();
- if (result.indexOf('$') != -1 && recursive) {
- result = expandString(result, recursive);
+ if (result.indexOf('$') != -1 && recursive && !expandedMacros.contains(result)) {
+ String prevResult = result;
+ expandedMacros.add(prevResult);
+ result = expandString(result, recursive, expandedMacros);
+ expandedMacros.remove(prevResult);
}
buffer.append(result);
} else {

Back to the top