Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Wolf2016-02-29 06:45:46 +0000
committerThomas Wolf2016-02-29 06:53:17 +0000
commit83ad11e2ff549487a8fb3352950266b663bc979b (patch)
treecc6eb20a8f4ebbb5b1d1aaeac98f48b192173f10
parent18bc49897a1bdc36d85798e14e0be4b9afa7dc03 (diff)
downloadegit-83ad11e2ff549487a8fb3352950266b663bc979b.tar.gz
egit-83ad11e2ff549487a8fb3352950266b663bc979b.tar.xz
egit-83ad11e2ff549487a8fb3352950266b663bc979b.zip
Safe preference reading of sash weights in GitHistoryPage
Preference values shall be treated as unverified external input and be read in paranoid mode. Preferences can become corrupted; we can't trust them. In no case shall garbled preferences cause the application to fail. Armor reading of sash weights and fall back to the default values if the stored values cannot be read. Bug: 488666 Change-Id: Ib22dbf855c9dde10108b6a90cc9ca7fcd7688966 Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIPreferences.java25
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java8
2 files changed, 27 insertions, 6 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIPreferences.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIPreferences.java
index c7a125f5ae..73f0af0c25 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIPreferences.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIPreferences.java
@@ -255,14 +255,29 @@ public class UIPreferences {
* the String value
* @param cnt
* number of entries in the returned array
- * @return the preference values for the array.
+ * @return the preference values for the array, or null if the string cannot
+ * be parsed or doesn't have {@code cnt} elements, or any value is
+ * <= 0.
*/
public static int[] stringToIntArray(final String value, final int cnt) {
+ if (value == null) {
+ return null;
+ }
+ final String[] values = value.split(","); //$NON-NLS-1$
+ if (values.length != cnt) {
+ return null;
+ }
final int[] r = new int[cnt];
- if (value != null) {
- final String[] e = value.split(","); //$NON-NLS-1$
- for (int i = 0; i < Math.min(e.length, r.length); i++)
- r[i] = Integer.parseInt(e[i].trim());
+ for (int i = 0; i < values.length; i++) {
+ try {
+ int val = Integer.parseInt(values[i].trim());
+ if (val <= 0) {
+ return null;
+ }
+ r[i] = val;
+ } catch (NumberFormatException e) {
+ return null;
+ }
}
return r;
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java
index 9bbfbf8e29..d8cc4e0233 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java
@@ -1028,7 +1028,13 @@ public class GitHistoryPage extends HistoryPage implements RefsChangedListener,
}
});
- sf.setWeights(UIPreferences.stringToIntArray(store.getString(key), 2));
+ int[] weights = UIPreferences.stringToIntArray(store.getString(key), 2);
+ if (weights == null) {
+ // Corrupted preferences?
+ weights = UIPreferences
+ .stringToIntArray(store.getDefaultString(key), 2);
+ }
+ sf.setWeights(weights);
}
private Composite createMainPanel(final Composite parent) {

Back to the top