/hg/icedtea-web: Validate the recently_used file at every load. ...
meyert at icedtea.classpath.org
meyert at icedtea.classpath.org
Tue Apr 10 10:16:32 PDT 2012
changeset 60ef5191add3 in /hg/icedtea-web
details: http://icedtea.classpath.org/hg/icedtea-web?cmd=changeset;node=60ef5191add3
author: Thomas Meyer <thomas at m3y3r.de>
date: Tue Apr 10 19:10:43 2012 +0200
Validate the recently_used file at every load. This will fix the StringIndex-
OutOfBoundsException for a corrupted path entry thrown in
CacheUtil.pathToURLPath(). This Exception was catched in
RessourceTracker.Downloader.run() and only printed in debug mode.
diffstat:
ChangeLog | 21 +
Makefile.am | 16 +-
netx/net/sourceforge/jnlp/cache/CacheLRUWrapper.java | 65 ++++-
netx/net/sourceforge/jnlp/cache/CacheUtil.java | 135 +++------
netx/net/sourceforge/jnlp/resources/Messages.properties | 9 +-
tests/jnlp_tests/signed/CacheReproducer/testcases/CacheReproducerTest.java | 93 +++++-
6 files changed, 217 insertions(+), 122 deletions(-)
diffs (truncated from 563 to 500 lines):
diff -r cde6d59a2901 -r 60ef5191add3 ChangeLog
--- a/ChangeLog Thu Apr 05 10:57:16 2012 -0400
+++ b/ChangeLog Tue Apr 10 19:10:43 2012 +0200
@@ -1,3 +1,24 @@
+2012-06-04 Jiri Vanek <jvanek at redhat.com>
+ Thomas Meyer <thomas at m3y3r.de>
+
+ * makefile.am: (stamps/run-netx-dist-tests.stamp) and
+ (run-reproducers-test-code-coverage.stamp)
+ now using $(javaws) variable instead of plaintext javaws
+ * netx/net/sourceforge/jnlp/cache/CacheLRUWrapper.java: (checkData) new
+ method checking for sanity of cache entries
+ (load) now checks for data sanity after loading, and stores without
+ corrupted items if necessary
+ (Comparator.compare) for sorting lru items. Now redundant checking for
+ sanity removed
+ * netx/net/sourceforge/jnlp/cache/CacheUtil.java: (getCacheFile) don't
+ call lruHandler.store twice for new cache entries
+ (getCacheFileIfExist) removed iteration and cleaning mechanism
+ * netx/net/sourceforge/jnlp/resources/Messages.properties: modified
+ cache messages
+ * tests/jnlp_tests/signed/CacheReproducer/testcases/CacheReproducerTest.java
+ Added test for checking corrupted path in entry and all tests adapted for
+ exception thrown only in debug mode
+
2012-04-04 Danesh Dadachanji <ddadacha at redhat.com>
Change the name of JarSigner to JarCertVerifier to make it more
relevant to the purpose of the file.
diff -r cde6d59a2901 -r 60ef5191add3 Makefile.am
--- a/Makefile.am Thu Apr 05 10:57:16 2012 -0400
+++ b/Makefile.am Tue Apr 10 19:10:43 2012 +0200
@@ -565,7 +565,7 @@
cd $(JNLP_TESTS_ENGINE_DIR) ; \
class_names=`cat $(REPRODUCERS_CLASS_NAMES)` ; \
CLASSPATH=$(NETX_DIR)/lib/classes.jar:$(JUNIT_JAR):$(JUNIT_RUNNER_JAR):. \
- $(BOOT_DIR)/bin/java -Dtest.server.dir=$(JNLP_TESTS_SERVER_DEPLOYDIR) -Djavaws.build.bin=$(DESTDIR)$(bindir)/javaws \
+ $(BOOT_DIR)/bin/java -Dtest.server.dir=$(JNLP_TESTS_SERVER_DEPLOYDIR) -Djavaws.build.bin=$(DESTDIR)$(bindir)/$(javaws) \
-Xbootclasspath:$(RUNTIME) CommandLine $$class_names \
> stdout.log 2> stderr.log ; \
cat stdout.log ; \
@@ -676,9 +676,9 @@
$(BOOT_DIR)/bin/jar -cf $(DESTDIR)$(datadir)/$(PACKAGE_NAME)/netx.jar * ; \
popd ; \
rm -rf $$instructed_dir ; \
- echo "patching javaws" ; \
- cat $$javaws_backup | sed "s,$(LAUNCHER_BOOTCLASSPATH),$$nw_bootclasspath," > $(DESTDIR)$(bindir)/javaws ; \
- chmod 777 $(DESTDIR)$(bindir)/javaws ; \
+ echo "patching $(javaws)" ; \
+ cat $$javaws_backup | sed "s,$(LAUNCHER_BOOTCLASSPATH),$$nw_bootclasspath," > $(DESTDIR)$(bindir)/$(javaws) ; \
+ chmod 777 $(DESTDIR)$(bindir)/$(javaws) ; \
testcases_srcs=( ) ; \
k=0 ; \
types=(simple signed); \
@@ -697,7 +697,7 @@
class_names=`cat $(REPRODUCERS_CLASS_NAMES)` ; \
$(BOOT_DIR)/bin/java \
-Dtest.server.dir=$(JNLP_TESTS_SERVER_DEPLOYDIR) \
- -Djavaws.build.bin=$(DESTDIR)$(bindir)/javaws \
+ -Djavaws.build.bin=$(DESTDIR)$(bindir)/$(javaws) \
-Xbootclasspath:$(RUNTIME) -cp $(EMMA_JAR) emmarun \
-raw \
-cp $(NETX_DIR)/lib/classes.jar \
@@ -727,9 +727,9 @@
-r xml \
"$${testcases_srcs[@]}" ; \
echo "restoring javaws and netx.jar in $(DESTDIR)" ; \
- rm -f $(DESTDIR)$(bindir)/javaws $(DESTDIR)$(datadir)/$(PACKAGE_NAME)/netx.jar ; \
- rm -f $(DESTDIR)$(bindir)/javaws; \
- mv $$javaws_backup $(DESTDIR)$(bindir)/javaws; \
+ rm -f $(DESTDIR)$(bindir)/$(javaws) $(DESTDIR)$(datadir)/$(PACKAGE_NAME)/netx.jar ; \
+ rm -f $(DESTDIR)$(bindir)/$(javaws); \
+ mv $$javaws_backup $(DESTDIR)$(bindir)/$(javaws); \
mv $$netx_backup $(DESTDIR)$(datadir)/$(PACKAGE_NAME)/netx.jar ; \
mv $(JNLP_TESTS_ENGINE_DIR)/tests-output.xml $(JNLP_TESTS_ENGINE_DIR)/tests-output_withEmma.xml ; \
mv $(JNLP_TESTS_ENGINE_DIR)/tests-output.xml_noEmma $(JNLP_TESTS_ENGINE_DIR)/tests-output.xml ; \
diff -r cde6d59a2901 -r 60ef5191add3 netx/net/sourceforge/jnlp/cache/CacheLRUWrapper.java
--- a/netx/net/sourceforge/jnlp/cache/CacheLRUWrapper.java Thu Apr 05 10:57:16 2012 -0400
+++ b/netx/net/sourceforge/jnlp/cache/CacheLRUWrapper.java Tue Apr 10 19:10:43 2012 +0200
@@ -36,6 +36,7 @@
*/
package net.sourceforge.jnlp.cache;
+import java.util.Set;
import static net.sourceforge.jnlp.runtime.Translator.R;
import java.io.File;
@@ -45,6 +46,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
+import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
@@ -107,6 +109,57 @@
*/
public synchronized void load() {
cacheOrder.load();
+ /*
+ * clean up possibly corrupted entries
+ */
+ if (checkData()) {
+ if (JNLPRuntime.isDebug()) {
+ new LruCacheException().printStackTrace();
+ }
+ System.out.println(R("CFakeCache"));
+ store();
+ System.out.println(R("CFakedCache"));
+ }
+ }
+
+ /**
+ * check content of cacheOrder and remove invalid/corrupt entries
+ *
+ * @return true, if cache was coruupted and affected entry removed
+ */
+ private boolean checkData () {
+ boolean modified = false;
+ Set<Entry<Object, Object>> q = cacheOrder.entrySet();
+ for (Iterator<Entry<Object, Object>> it = q.iterator(); it.hasNext();) {
+ Entry<Object, Object> currentEntry = it.next();
+
+ final String key = (String) currentEntry.getKey();
+ final String path = (String) currentEntry.getValue();
+
+ // 1. check key format: "milliseconds,number"
+ try {
+ String sa[] = key.split(",");
+ Long l1 = Long.parseLong(sa[0]);
+ Long l2 = Long.parseLong(sa[1]);
+ } catch (Exception ex) {
+ it.remove();
+ modified = true;
+ continue;
+ }
+
+ // 2. check path format - does the path look correct?
+ if (path != null) {
+ if (path.indexOf(cacheDir) < 0) {
+ it.remove();
+ modified = true;
+ }
+ } else {
+ it.remove();
+ modified = true;
+ }
+ }
+
+ return modified;
}
/**
@@ -174,15 +227,11 @@
Collections.sort(entries, new Comparator<Entry<String, String>>() {
@Override
public int compare(Entry<String, String> e1, Entry<String, String> e2) {
- try {
- Long t1 = Long.parseLong(e1.getKey().split(",")[0]);
- Long t2 = Long.parseLong(e2.getKey().split(",")[0]);
+ Long t1 = Long.parseLong(e1.getKey().split(",")[0]);
+ Long t2 = Long.parseLong(e2.getKey().split(",")[0]);
- int c = t1.compareTo(t2);
- return c < 0 ? 1 : (c > 0 ? -1 : 0);
- } catch (Exception e) {
- throw new LruCacheException(R("Corrupt LRU file entries"));
- }
+ int c = t1.compareTo(t2);
+ return c < 0 ? 1 : (c > 0 ? -1 : 0);
}
});
return entries;
diff -r cde6d59a2901 -r 60ef5191add3 netx/net/sourceforge/jnlp/cache/CacheUtil.java
--- a/netx/net/sourceforge/jnlp/cache/CacheUtil.java Thu Apr 05 10:57:16 2012 -0400
+++ b/netx/net/sourceforge/jnlp/cache/CacheUtil.java Tue Apr 10 19:10:43 2012 +0200
@@ -307,8 +307,8 @@
cacheFile = getCacheFileIfExist(urlToPath(source, ""));
if (cacheFile == null) { // We did not find a copy of it.
cacheFile = makeNewCacheFile(source, version);
- }
- lruHandler.store();
+ } else
+ lruHandler.store();
lruHandler.unlock();
}
return cacheFile;
@@ -323,48 +323,16 @@
private static File getCacheFileIfExist(File urlPath) {
synchronized (lruHandler) {
File cacheFile = null;
- int tries = 0;
- List<Entry<String, String>> entries = null;
- do {
- try {
- tries++;
- entries = lruHandler.getLRUSortedEntries();
- } catch (LruCacheException ex) {
- if (tries == 1) {
- ex.printStackTrace();
- System.out.println(R("CFakeCache"));
- lruHandler.clearLRUSortedEntries();
- lruHandler.store();
- System.out.println(R("CFakedCache"));
- } else if (tries == 2) {
- ex.printStackTrace();
- System.out.println(R("CStillCorupted"));
- boolean clearingresult = CacheUtil.clearCache();
- if (!clearingresult) {
- throw new InternalError(R("CCleaningUnsuccessful"));
- }
- System.out.println(R("CClearedReloading"));
- lruHandler.clearLRUSortedEntries();
- lruHandler.store();
- System.out.println(R("CReloadRestarting"));
-
- } else {
- throw new InternalError(R("CStillBroken"));
- }
-
- }
- } while (entries == null);
+ List<Entry<String, String>> entries = lruHandler.getLRUSortedEntries();
// Start searching from the most recent to least recent.
for (Entry<String, String> e : entries) {
final String key = e.getKey();
final String path = e.getValue();
- if (path != null) {
- if (pathToURLPath(path).equals(urlPath.getPath())) { // Match found.
- cacheFile = new File(path);
- lruHandler.updateEntry(key);
- break; // Stop searching since we got newest one already.
- }
+ if (pathToURLPath(path).equals(urlPath.getPath())) { // Match found.
+ cacheFile = new File(path);
+ lruHandler.updateEntry(key);
+ break; // Stop searching since we got newest one already.
}
}
return cacheFile;
@@ -561,6 +529,7 @@
* This will remove all old cache items.
*/
public static void cleanCache() {
+
if (okToClearCache()) {
// First we want to figure out which stuff we need to delete.
HashSet<String> keep = new HashSet<String>();
@@ -579,57 +548,55 @@
for (Entry<String, String> e : lruHandler.getLRUSortedEntries()) {
// Check if the item is contained in cacheOrder.
final String key = e.getKey();
- final String value = e.getValue();
+ final String path = e.getValue();
- if (value != null) {
- File file = new File(value);
- PropertiesFile pf = new PropertiesFile(new File(value + ".info"));
- boolean delete = Boolean.parseBoolean(pf.getProperty("delete"));
+ File file = new File(path);
+ PropertiesFile pf = new PropertiesFile(new File(path + ".info"));
+ boolean delete = Boolean.parseBoolean(pf.getProperty("delete"));
- /*
- * This will get me the root directory specific to this cache item.
- * Example:
- * cacheDir = /home/user1/.icedtea/cache
- * file.getPath() = /home/user1/.icedtea/cache/0/http/www.example.com/subdir/a.jar
- * rStr first becomes: /0/http/www.example.com/subdir/a.jar
- * then rstr becomes: /home/user1/.icedtea/cache/0
- */
- String rStr = file.getPath().substring(cacheDir.length());
- rStr = cacheDir + rStr.substring(0, rStr.indexOf(File.separatorChar, 1));
- long len = file.length();
+ /*
+ * This will get me the root directory specific to this cache item.
+ * Example:
+ * cacheDir = /home/user1/.icedtea/cache
+ * file.getPath() = /home/user1/.icedtea/cache/0/http/www.example.com/subdir/a.jar
+ * rStr first becomes: /0/http/www.example.com/subdir/a.jar
+ * then rstr becomes: /home/user1/.icedtea/cache/0
+ */
+ String rStr = file.getPath().substring(cacheDir.length());
+ rStr = cacheDir + rStr.substring(0, rStr.indexOf(File.separatorChar, 1));
+ long len = file.length();
- if (keep.contains(file.getPath().substring(rStr.length()))) {
- lruHandler.removeEntry(key);
- continue;
- }
-
- /*
- * we remove entries from our lru if any of the following condition is met.
- * Conditions:
- * - delete: file has been marked for deletion.
- * - !file.isFile(): if someone tampered with the directory, file doesn't exist.
- * - maxSize >= 0 && curSize + len > maxSize: If a limit was set and the new size
- * on disk would exceed the maximum size.
- */
- if (delete || !file.isFile() || (maxSize >= 0 && curSize + len > maxSize)) {
- lruHandler.removeEntry(key);
- remove.add(rStr);
- } else {
- curSize += len;
- keep.add(file.getPath().substring(rStr.length()));
+ if (keep.contains(file.getPath().substring(rStr.length()))) {
+ lruHandler.removeEntry(key);
+ continue;
+ }
- for (File f : file.getParentFile().listFiles()) {
- if (!(f.equals(file) || f.equals(pf.getStoreFile()))){
- try {
- FileUtils.recursiveDelete(f, f);
- } catch (IOException e1) {
- e1.printStackTrace();
- }
- }
+ /*
+ * we remove entries from our lru if any of the following condition is met.
+ * Conditions:
+ * - delete: file has been marked for deletion.
+ * - !file.isFile(): if someone tampered with the directory, file doesn't exist.
+ * - maxSize >= 0 && curSize + len > maxSize: If a limit was set and the new size
+ * on disk would exceed the maximum size.
+ */
+ if (delete || !file.isFile() || (maxSize >= 0 && curSize + len > maxSize)) {
+ lruHandler.removeEntry(key);
+ remove.add(rStr);
+ continue;
+ }
+
+ curSize += len;
+ keep.add(file.getPath().substring(rStr.length()));
+
+ for (File f : file.getParentFile().listFiles()) {
+ if (!(f.equals(file) || f.equals(pf.getStoreFile()))) {
+ try {
+ FileUtils.recursiveDelete(f, f);
+ } catch (IOException e1) {
+ e1.printStackTrace();
}
}
- } else {
- lruHandler.removeEntry(key);
+
}
}
lruHandler.store();
diff -r cde6d59a2901 -r 60ef5191add3 netx/net/sourceforge/jnlp/resources/Messages.properties
--- a/netx/net/sourceforge/jnlp/resources/Messages.properties Thu Apr 05 10:57:16 2012 -0400
+++ b/netx/net/sourceforge/jnlp/resources/Messages.properties Tue Apr 10 19:10:43 2012 +0200
@@ -192,13 +192,8 @@
CChooseCacheInfo=Netx needs a location for storing cache files.
CChooseCacheDir=Cache directory
CCannotClearCache=Can not clear cache at this time
-CFakeCache=Cache is corrupt. Disabling.
-CFakedCache=Cache is corrupt and has been disabled. It is strongly recommended that you run 'javaws -Xclearcache' and rerun your application as soon as possible.
-CStillCorupted=Cache is still corrupt, clearing it.
-CCleaningUnsuccessful=Unable to clear cache due to running javaws instance. Please try to shut down all instances of javaws, run 'javaws -Xclearcache', and rerun your jnlp file
-CClearedReloading=Cache cleared, re-loading.
-CReloadRestarting=Cache re-loaded and application re-starting. It is strongly recommended that you run 'javaws -Xclearcache' and re-run your application as soon as possible.
-CStillBroken=Unable to fix corrupt cache. Please shutdown all javaws instances, run 'javaws -Xclearcache', and re-start your application.
+CFakeCache=Cache is corrupt. Fixing.
+CFakedCache=Cache is corrupt and has been fixed. It is strongly recommended that you run 'javaws -Xclearcache' and rerun your application as soon as possible.
# Security
SFileReadAccess=The application has requested read access to {0}. Do you want to allow this action?
diff -r cde6d59a2901 -r 60ef5191add3 tests/jnlp_tests/signed/CacheReproducer/testcases/CacheReproducerTest.java
--- a/tests/jnlp_tests/signed/CacheReproducer/testcases/CacheReproducerTest.java Thu Apr 05 10:57:16 2012 -0400
+++ b/tests/jnlp_tests/signed/CacheReproducer/testcases/CacheReproducerTest.java Tue Apr 10 19:10:43 2012 +0200
@@ -57,7 +57,8 @@
private static final ServerAccess server = new ServerAccess();
private static final List<String> clear = Arrays.asList(new String[]{server.getJavawsLocation(), "-Xclearcache", ServerAccess.HEADLES_OPTION});
- private static final List<String> trusted = Arrays.asList(new String[]{"-Xtrustall", ServerAccess.HEADLES_OPTION});
+ private static final List<String> trustedVerboses = Arrays.asList(new String[]{"-Xtrustall", ServerAccess.HEADLES_OPTION,"-verbose"});
+ private static final List<String> verbosed = Arrays.asList(new String[]{"-verbose", ServerAccess.HEADLES_OPTION});
private static final String home = System.getProperty("user.home");
private static final String name = System.getProperty("user.name");
private static final String tmp = System.getProperty("java.io.tmpdir");
@@ -66,10 +67,17 @@
private static final File icedteaCacheFile = new File(icedteaCache, "recently_used");
private static final File netxLock = new File(tmp + "/" + name + "/netx/locks/netx_running");
private static final String lre = "LruCacheException";
+ private static final String ioobe = "IndexOutOfBoundsException";
private static final String corruptRegex = "\\d{13}";
private static final Pattern corruptPatern = Pattern.compile(corruptRegex);
private static final String corruptString = "156dsf1562kd5";
+ String testS = "#netx file\n"
+ + "#Mon Dec 12 16:20:46 CET 2011\n"
+ + "1323703236508,0=/home/xp13/.icedtea/cache/0/http/localhost/ReadPropertiesBySignedHack.jnlp\n"
+ + "1323703243086,2=/home/xp14/.icedtea/cache/2/http/localhost/ReadProperties.jar\n"
+ + "1323703243082,1=/home/xp15/.icedtea/cache/1/http/localhost/ReadPropertiesBySignedHack.jar";
+
@Test
public void cacheIsWorkingTest() throws Exception {
clearAndEvaluateCache();
@@ -131,6 +139,10 @@
Assert.assertTrue("icedtea cache file " + icedteaCacheFile.getAbsolutePath() + " should not be empty", icedteaCacheFile.length() > 0);
}
+ /**
+ * This is breaking integer numbers in first part of cache file item
+ * @throws Exception
+ */
@Test
public void coruptAndRunCache1() throws Exception {
clearAndEvaluateCache();
@@ -146,9 +158,13 @@
assertLruExceptionNOTappeared(pr2);
}
+ /**
+ * This is breaking integer numbers in first part of cache file item
+ * @throws Exception
+ */
@Test
public void coruptAndRunCache2() throws Exception {
- clearAndEvaluateCache();
+ clearAndEvaluateCache();
evaluateSimpleTest1OkCache(runSimpleTest1());
assertCacheIsNotEmpty();
breakCache1();
@@ -164,6 +180,33 @@
assertLruExceptionNOTappeared(pr2);
}
+ /**
+ * This is breaking paths in second part of cache file item
+ * @throws Exception
+ */
+ @Test
+ public void coruptAndRunCache3() throws Exception {
+ clearAndEvaluateCache();
+ evaluateSimpleTest1OkCache(runSimpleTest1());
+ assertCacheIsNotEmpty();
+ breakCache3();
+ ProcessResult pr = runSimpleTest1();
+ assertAoobNOTappeared(pr);
+ assertLruExceptionAppeared(pr);
+ evaluateSimpleTest1OkCache(pr);
+ ProcessResult pr3 = runSimpleTest1();
+ evaluateSimpleTest1OkCache(pr3);
+ assertLruExceptionNOTappeared(pr3);
+ clearAndEvaluateCache();
+ ProcessResult pr2 = runSimpleTest1();
+ evaluateSimpleTest1OkCache(pr2);
+ assertLruExceptionNOTappeared(pr2);
+ }
+
+ private void assertAoobNOTappeared(ProcessResult pr2) {
+ Assert.assertFalse("serr should NOT contain " + ioobe, pr2.stderr.contains(ioobe));
+ }
+
private void assertLruExceptionNOTappeared(ProcessResult pr2) {
Assert.assertFalse("serr should NOT contain " + lre, pr2.stderr.contains(lre));
}
@@ -174,7 +217,7 @@
@Test
public void coruptAndRunCache1Signed() throws Exception {
- clearAndEvaluateCache();
+ clearAndEvaluateCache();
evaluateSimpleTest1OkCache(runSimpleTest1());
assertCacheIsNotEmpty();
breakCache1();
@@ -189,7 +232,7 @@
@Test
public void coruptAndRunCache2Signed() throws Exception {
- clearAndEvaluateCache();
+ clearAndEvaluateCache();
evaluateSimpleTest1OkCache(runSimpleTest1());
assertCacheIsNotEmpty();
breakCache1();
@@ -217,7 +260,7 @@
try {
System.out.println("connecting deadlocktest request");
System.err.println("connecting deadlocktest request");
- ServerAccess.ProcessResult pr = server.executeJavawsHeadless(null, "/deadlocktest.jnlp");
+ ServerAccess.ProcessResult pr = server.executeJavawsHeadless(verbosed, "/deadlocktest.jnlp");
System.out.println(pr.stdout);
System.err.println(pr.stderr);
} catch (Exception ex) {
@@ -236,7 +279,7 @@
}
- //next four tests are designed to ensure, that corupted cache wil not break already loaded cached files
+ //next four tests are designed to ensure, that corrupted cache will not break already loaded cached files
public static final String CR1 = "CacheReproducer1";
public static final String CR2 = "CacheReproducer2";
public static final String CR11 = "CacheReproducer1_1";
@@ -327,14 +370,9 @@
}
@Test
- public void assertBreakersAreWorking() {
More information about the distro-pkg-dev
mailing list