aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCamilo Bernal2012-12-13 09:53:23 (EST)
committerSami Wagiaalla2012-12-14 16:20:46 (EST)
commit4aa78cdfefebdfc4a6c17df1fb76c7421a914dd1 (patch)
tree26e4183d3797cdc9b59a7cf116fee7ecec43101a
parentf9ba572351d039d48ef544e13217c6a52d5344be (diff)
downloadorg.eclipse.linuxtools-4aa78cdfefebdfc4a6c17df1fb76c7421a914dd1.zip
org.eclipse.linuxtools-4aa78cdfefebdfc4a6c17df1fb76c7421a914dd1.tar.gz
org.eclipse.linuxtools-4aa78cdfefebdfc4a6c17df1fb76c7421a914dd1.tar.bz2
Bug 396505: Open Error Dialog when stap script name is of improper form.refs/changes/20/9220/6
Stop script execution and open error dialog when script name is not of the form ^[a-z0-9_]+(.stp)$ . This a temporary fix, the stap tool itself should handle module naming in the future. Change-Id: Id8e92c642f9f539d6fee64a9fe2f48c7221b699a Reviewed-on: https://git.eclipse.org/r/9220 Reviewed-by: Sami Wagiaalla <swagiaal@redhat.com> IP-Clean: Sami Wagiaalla <swagiaal@redhat.com> Tested-by: Sami Wagiaalla <swagiaal@redhat.com>
-rw-r--r--systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/systemtap/ui/ide/actions/Messages.java16
-rw-r--r--systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/systemtap/ui/ide/actions/RunScriptBaseAction.java25
-rw-r--r--systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/systemtap/ui/ide/actions/messages.properties2
3 files changed, 39 insertions, 4 deletions
diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/systemtap/ui/ide/actions/Messages.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/systemtap/ui/ide/actions/Messages.java
new file mode 100644
index 0000000..8b54e81
--- /dev/null
+++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/systemtap/ui/ide/actions/Messages.java
@@ -0,0 +1,16 @@
+package org.eclipse.linuxtools.systemtap.ui.ide.actions;
+
+import org.eclipse.osgi.util.NLS;
+
+public class Messages extends NLS {
+ private static final String BUNDLE_NAME = "org.eclipse.linuxtools.systemtap.ui.ide.actions.messages"; //$NON-NLS-1$
+ public static String ScriptRunAction_InvalidScriptTitle;
+ public static String ScriptRunAction_InvalidScriptTMessage;
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/systemtap/ui/ide/actions/RunScriptBaseAction.java b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/systemtap/ui/ide/actions/RunScriptBaseAction.java
index 54a78d7..b3a1ba2 100644
--- a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/systemtap/ui/ide/actions/RunScriptBaseAction.java
+++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/systemtap/ui/ide/actions/RunScriptBaseAction.java
@@ -16,6 +16,8 @@ import java.io.FileReader;
import java.io.IOException;
import java.text.MessageFormat;
import java.util.ArrayList;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IAction;
@@ -37,6 +39,7 @@ import org.eclipse.linuxtools.systemtap.ui.ide.structures.TapsetLibrary;
import org.eclipse.linuxtools.systemtap.ui.structures.PasswordPrompt;
import org.eclipse.linuxtools.systemtap.ui.systemtapgui.preferences.EnvironmentVariablesPreferencePage;
import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
import org.eclipse.ui.PlatformUI;
@@ -283,7 +286,7 @@ abstract public class RunScriptBaseAction extends Action implements IWorkbenchWi
String modname;
if(getRunLocal() == false) {
- modname = serverfileName.substring(0, serverfileName.indexOf('.'));
+ modname = serverfileName.substring(0, serverfileName.lastIndexOf(".stp")); //$NON-NLS-1$
}
/* We need to remove the directory prefix here because in the case of
* running the script remotely, this is already done. Not doing so
@@ -291,10 +294,24 @@ abstract public class RunScriptBaseAction extends Action implements IWorkbenchWi
*/
else {
modname = fileName.substring(fileName.lastIndexOf('/')+1);
- modname = modname.substring(0, modname.indexOf('.'));
+ modname = modname.substring(0, modname.lastIndexOf(".stp")); //$NON-NLS-1$
}
- if (modname.indexOf('-') != -1)
- modname = modname.substring(0, modname.indexOf('-'));
+
+ // Make sure script name only contains underscores and/or alphanumeric characters.
+ Pattern validModName = Pattern.compile("^[a-z0-9_]+$"); //$NON-NLS-1$
+ Matcher modNameMatch = validModName.matcher(modname);
+ if (!modNameMatch.matches()) {
+ continueRun = false;
+
+ Shell parent = PlatformUI.getWorkbench().getDisplay()
+ .getActiveShell();
+ MessageDialog.openError(parent,
+ Messages.ScriptRunAction_InvalidScriptTitle,
+ Messages.ScriptRunAction_InvalidScriptTMessage);
+
+ return new String[0];
+ }
+
script[script.length-2]=modname;
return script;
}
diff --git a/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/systemtap/ui/ide/actions/messages.properties b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/systemtap/ui/ide/actions/messages.properties
new file mode 100644
index 0000000..5e7e962
--- /dev/null
+++ b/systemtap/org.eclipse.linuxtools.systemtap.ui.ide/src/org/eclipse/linuxtools/systemtap/ui/ide/actions/messages.properties
@@ -0,0 +1,2 @@
+ScriptRunAction_InvalidScriptTitle=Invalid Script Name
+ScriptRunAction_InvalidScriptTMessage=Script name must only contain characters 'a'-'z', '0'-'9' and '_' \ No newline at end of file