Mercurial > hg > release > icedtea-web-1.6
changeset 1275:51dd6ea0aed0
Small properties parser in C (plugin) now unescapes \= \\ \: \t \n and \r correctly
author | Jiri Vanek <jvanek@redhat.com> |
---|---|
date | Wed, 23 Dec 2015 13:58:39 +0100 |
parents | 67a3d4c59e19 |
children | ee907deeda19 |
files | ChangeLog plugin/icedteanp/IcedTeaParseProperties.cc plugin/icedteanp/IcedTeaPluginUtils.cc plugin/icedteanp/IcedTeaPluginUtils.h tests/cpp-unit-tests/IcedTeaParsePropertiesTest.cc tests/cpp-unit-tests/IcedTeaPluginUtilsTest.cc tests/reproducers/signed/CheckPluginParams/resources/CheckPluginParams.jnlp tests/reproducers/signed/CheckPluginParams/resources/CheckPluginParams1.html tests/reproducers/signed/CheckPluginParams/resources/CheckPluginParams2.html tests/reproducers/signed/CheckPluginParams/srcs/CheckPluginParams.java tests/reproducers/signed/CheckPluginParams/testcases/CheckPluginParamsTests.java |
diffstat | 11 files changed, 414 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Wed Dec 02 09:01:34 2015 +0100 +++ b/ChangeLog Wed Dec 23 13:58:39 2015 +0100 @@ -1,3 +1,18 @@ +2015-12-23 Jiri Vanek <jvanek@redhat.com> + + Small properties parser in C (plugin) now unescapes \= \\ \: \t \n and \r correctly + * plugin/icedteanp/IcedTeaParseProperties.cc: (get_property_value) now unescape + known escape sequences by calling IcedTeaPluginUtilities::unescape + * plugin/icedteanp/IcedTeaPluginUtils.cc: implemented (unescape) which unescape + known properties escape sequences + * plugin/icedteanp/IcedTeaPluginUtils.h: declared (unescape) + * tests/cpp-unit-tests/IcedTeaParsePropertiesTest.cc: ((get_property_value)) + added testcase which verifies unnescape of escaped sequences from get_property_value + * tests/cpp-unit-tests/IcedTeaPluginUtilsTest.cc: added family of (unescape) tests + * /tests/reproducers/signed/CheckPluginParams: reproducer to verify if params + from -D in deployment.plugin.jvm.arguments get correctly unescaped during its + way up to users program. + 2015-11-26 Jiri Vanek <jvanek@redhat.com> Main-class attribute get trimmed by default
--- a/plugin/icedteanp/IcedTeaParseProperties.cc Wed Dec 02 09:01:34 2015 +0100 +++ b/plugin/icedteanp/IcedTeaParseProperties.cc Wed Dec 23 13:58:39 2015 +0100 @@ -95,6 +95,7 @@ int l = c.length(); dest = c.substr(i+1, l-i); IcedTeaPluginUtilities::trim(dest); + IcedTeaPluginUtilities::unescape(dest); return true; }
--- a/plugin/icedteanp/IcedTeaPluginUtils.cc Wed Dec 02 09:01:34 2015 +0100 +++ b/plugin/icedteanp/IcedTeaPluginUtils.cc Wed Dec 23 13:58:39 2015 +0100 @@ -1148,6 +1148,55 @@ str = str.substr(start, end - start + 1); } +/*Unescape various escaped chars like \\ -> \ or \= -> = or \: -> , \t -> TAB , \n -> NwLine\*/ + +/* examples + * \\= -> \= + * \= -> = + * \\ -> \ + * \e -> \e + * \: -> : + * \ -> \ + * \\ -> \ + */ +void IcedTeaPluginUtilities::unescape(std::string& str) { + std::string result = ""; + int len = str.length(); + for (unsigned int i = 0; i < len; i++) { + bool processed = false; + char c1 = str[i]; + if (c1 == '\\') { + if (i < len - 1) { + char c2 = str[i + 1]; + if (c2 == '=' || c2 == '\\' || c2 == ':') { + result += c2; + i++; + processed = true; + } + if (c2 == 't') { + result += '\t'; + i++; + processed = true; + } + if (c2 == 'n') { + result += '\n'; + i++; + processed = true; + } + if (c2 == 'r') { + result += '\r'; + i++; + processed = true; + } + } + } + if (!processed) { + result += c1; + } + } + str = result; +} + std::string IcedTeaPluginUtilities::NPIdentifierAsString(NPIdentifier id) { NPUTF8* cstr = browser_functions.utf8fromidentifier(id); if (cstr == NULL) {
--- a/plugin/icedteanp/IcedTeaPluginUtils.h Wed Dec 02 09:01:34 2015 +0100 +++ b/plugin/icedteanp/IcedTeaPluginUtils.h Wed Dec 23 13:58:39 2015 +0100 @@ -431,6 +431,8 @@ /*cutting whitespaces from end and start of string*/ static void trim(std::string& str); + /*Unescape various escaped chars like \\ -> \ or \= -> = or \: -> \*/ + static void unescape(std::string& str); static bool file_exists(std::string filename); static bool is_directory(std::string filename); //file-loggers helpers
--- a/tests/cpp-unit-tests/IcedTeaParsePropertiesTest.cc Wed Dec 02 09:01:34 2015 +0100 +++ b/tests/cpp-unit-tests/IcedTeaParsePropertiesTest.cc Wed Dec 23 13:58:39 2015 +0100 @@ -119,6 +119,11 @@ a = get_property_value("better.key but errornous value ",dest); CHECK_EQUAL("", dest); CHECK_EQUAL(a, false); + + dest = string(""); + a = get_property_value("key=nice\\=value=\\\\=with\\tescapes",dest); + CHECK_EQUAL("nice=value=\\=with\tescapes", dest); + CHECK_EQUAL(a, true); } TEST(starts_with) {
--- a/tests/cpp-unit-tests/IcedTeaPluginUtilsTest.cc Wed Dec 02 09:01:34 2015 +0100 +++ b/tests/cpp-unit-tests/IcedTeaPluginUtilsTest.cc Wed Dec 23 13:58:39 2015 +0100 @@ -115,6 +115,29 @@ CHECK_EQUAL("te \n stX", toBeTrimmed3); } +TEST(unescape1) { + std::string toBeEscaped = std::string("he\\\\=llo\\=my=boy\\\\ who :liv\\es in\\: space \\ and \\\\likes\\"); + /*he\\=llo\=my=boy\\ who :liv\es in\: space \ and \\likes\ */ + IcedTeaPluginUtilities::unescape(toBeEscaped); + /* \\= -> \= , \= -> = , \\ -> \ , \e -> \e , \: -> : , \ -> \ , \\ -> \*/ + /*he\=llo=my=boy\ who :liv\es in: space \ and \likes\ */ + CHECK_EQUAL("he\\=llo=my=boy\\ who :liv\\es in: space \\ and \\likes\\", toBeEscaped); +} + +TEST(unescape2) { + std::string toBeEscaped = std::string("w1\\tw2\\\\tw3\\nw4\\\\nw5\\="); + /*w1\tw2\\tw3\nw4\\nw5\=*/ + IcedTeaPluginUtilities::unescape(toBeEscaped); + /*w1TABw2\tw3NWLINEw4\nw5=*/ + CHECK_EQUAL("w1\tw2\\tw3\nw4\\nw5=", toBeEscaped); +} + +TEST(unescape3) { + std::string toBeEscaped = std::string("w1\\rw2\\\\rw3="); + IcedTeaPluginUtilities::unescape(toBeEscaped); + CHECK_EQUAL("w1\rw2\\rw3=", toBeEscaped); +} + /* Creates a temporary file with the specified contents */ static std::string temporary_file(const std::string& contents) {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/reproducers/signed/CheckPluginParams/resources/CheckPluginParams.jnlp Wed Dec 23 13:58:39 2015 +0100 @@ -0,0 +1,57 @@ +<!-- + +This file is part of IcedTea. + +IcedTea is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +IcedTea is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with IcedTea; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. + + --> +<?xml version="1.0" encoding="utf-8"?> +<jnlp spec="1.0" href="CheckPluginParams.jnlp" codebase="."> + <information> + <title>CheckPluginParams</title> + <vendor>IcedTea</vendor> + <homepage href="http://icedtea.classpath.org/wiki/IcedTea-Web#Testing_IcedTea-Web"/> + <description>CheckPluginParams</description> + <offline/> + </information> + <resources> + <j2se version="1.4+"/> + <jar href="CheckPluginParams.jar"/> + </resources> + <applet-desc + documentBase="." + name="CheckPluginParams" + main-class="CheckPluginParams" + width="100" + height="100" /> +</jnlp>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/reproducers/signed/CheckPluginParams/resources/CheckPluginParams1.html Wed Dec 23 13:58:39 2015 +0100 @@ -0,0 +1,46 @@ +<!-- + +This file is part of IcedTea. + +IcedTea is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +IcedTea is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with IcedTea; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. + +--> +<html> + <head></head> + <body> + <applet code="CheckPluginParams" width="800" height="600"> + <param name="jnlp_href" value="CheckPluginParams.jnlp"> + </applet> + </body> +</html> +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/reproducers/signed/CheckPluginParams/resources/CheckPluginParams2.html Wed Dec 23 13:58:39 2015 +0100 @@ -0,0 +1,45 @@ +<!-- + +This file is part of IcedTea. + +IcedTea is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +IcedTea is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with IcedTea; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. + +--> +<html> + <head></head> + <body> + <applet code="CheckPluginParams.class" archive="CheckPluginParams.jar" codebase="." width="800" height="600"> + </applet> + </body> +</html> +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/reproducers/signed/CheckPluginParams/srcs/CheckPluginParams.java Wed Dec 23 13:58:39 2015 +0100 @@ -0,0 +1,69 @@ +/* CheckPluginParams.java +Copyright (C) 2012 Red Hat, Inc. + +This file is part of IcedTea. + +IcedTea is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License as published by +the Free Software Foundation, version 2. + +IcedTea is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with IcedTea; see the file COPYING. If not, write to +the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. + */ + + +import java.applet.Applet; + +public class CheckPluginParams extends Applet { + + private static final String ID ="test.custom"; + + public static void main(String... args){ + System.out.println(""+ID+"1: "+System.getProperty(""+ID+"1")); + System.out.println(""+ID+"2: "+System.getProperty(""+ID+"2")); + System.out.println(""+ID+"3: "+System.getProperty(""+ID+"3")); + System.out.println(""+ID+"4: "+System.getProperty(""+ID+"4")); + } + + + @Override + public void init() { + main(); + + } + + @Override + public void start() { + //main(); + System.out.println("*** APPLET FINISHED ***"); + + } + + + + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/reproducers/signed/CheckPluginParams/testcases/CheckPluginParamsTests.java Wed Dec 23 13:58:39 2015 +0100 @@ -0,0 +1,102 @@ +/* CheckPluginParamsTests.java + Copyright (C) 2012 Red Hat, Inc. + + This file is part of IcedTea. + + IcedTea is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as published by + the Free Software Foundation, version 2. + + IcedTea is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with IcedTea; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. + + Linking this library statically or dynamically with other modules is + making a combined work based on this library. Thus, the terms and + conditions of the GNU General Public License cover the whole + combination. + + As a special exception, the copyright holders of this library give you + permission to link this library with independent modules to produce an + executable, regardless of the license terms of these independent + modules, and to copy and distribute the resulting executable under + terms of your choice, provided that you also meet, for each linked + independent module, the terms and conditions of the license of that + module. An independent module is a module which is not derived from + or based on this library. If you modify this library, you may extend + this exception to your version of the library, but you are not + obligated to do so. If you do not wish to do so, delete this + exception statement from your version. + */ + +import java.io.IOException; +import net.sourceforge.jnlp.ProcessResult; +import net.sourceforge.jnlp.annotations.Bug; +import net.sourceforge.jnlp.annotations.NeedsDisplay; +import net.sourceforge.jnlp.annotations.TestInBrowsers; +import net.sourceforge.jnlp.browsertesting.BrowserTest; +import net.sourceforge.jnlp.browsertesting.Browsers; +import net.sourceforge.jnlp.closinglisteners.AutoErrorClosingListener; +import net.sourceforge.jnlp.closinglisteners.AutoOkClosingListener; +import net.sourceforge.jnlp.config.DeploymentConfiguration; +import net.sourceforge.jnlp.tools.DeploymentPropertiesModifier; +import org.junit.AfterClass; + +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +@Bug(id = "RH1273691") +public class CheckPluginParamsTests extends BrowserTest { + + private static DeploymentPropertiesModifier d; + private static final String ID = "test.custom"; + + @BeforeClass + public static void setup() throws IOException { + String value + = " -D" + ID + "1=value1" + + " -D" + ID + "2\\=value2=value2" + + " -D" + ID + "3=value3\\=value3" + + " -D" + ID + "4\\=value4\\\\=value4"; + d = new DeploymentPropertiesModifier(); + d.setProperties(DeploymentConfiguration.KEY_PLUGIN_JVM_ARGUMENTS, value); + } + + @AfterClass + public static void tearDown() throws IOException { + d.restoreProperties(); + } + + public void evaluateApplet(ProcessResult pr) { + String s = pr.stdout; + Assert.assertTrue(s.contains(ID + "1: value1")); + Assert.assertTrue(s.contains(ID + "2: value2=value2")); + Assert.assertTrue(s.contains(ID + "3: value3=value3")); + Assert.assertTrue(s.contains(ID + "4: value4\\=value4")); + } + + @Bug(id = "RH1273691") + @Test + @NeedsDisplay + @TestInBrowsers(testIn = {Browsers.one}) + public void CheckWebstartServices() throws Exception { + ProcessResult pr = server.executeBrowser(null, "/CheckPluginParams1.html", new AutoOkClosingListener(), new AutoErrorClosingListener()); + evaluateApplet(pr); + } + + @Bug(id = "RH1273691") + @Test + @NeedsDisplay + @TestInBrowsers(testIn = {Browsers.one}) + public void CheckPluginJNLPHServices() throws Exception { + ProcessResult pr = server.executeBrowser(null, "/CheckPluginParams2.html", new AutoOkClosingListener(), new AutoErrorClosingListener()); + evaluateApplet(pr); + } +}