Skip to content

Commit

Permalink
Viewer: Truncate overly long conn. history strings
Browse files Browse the repository at this point in the history
Java Preferences values cannot be more than Preferences.MAX_VALUE_LENGTH
(usually 8192) characters in length.  Attempting to store a longer
string into a Preferences node results in an IllegalArgumentException.

Fixes #410
  • Loading branch information
dcommander committed May 1, 2024
1 parent 7ec473f commit f4c9324
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions java/com/turbovnc/vncviewer/ServerDialog.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* Copyright (C) 2012-2015, 2018, 2020 D. R. Commander. All Rights Reserved.
/* Copyright (C) 2012-2015, 2018, 2020, 2024 D. R. Commander.
* All Rights Reserved.
* Copyright (C) 2011-2013 Brian P. Hinz
* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
*
Expand Down Expand Up @@ -26,6 +27,7 @@
import javax.swing.border.*;
import javax.swing.WindowConstants.*;
import java.util.*;
import java.util.prefs.Preferences;

import com.turbovnc.rdr.*;
import com.turbovnc.rfb.*;
Expand Down Expand Up @@ -246,7 +248,16 @@ private boolean commit() {
sb.append(str);
}
}
UserPreferences.set("ServerDialog", "history", sb.toString());
String history = sb.toString();
if (history.length() > Preferences.MAX_VALUE_LENGTH) {
int lastComma =
history.lastIndexOf(',', Preferences.MAX_VALUE_LENGTH);
if (lastComma <= 0)
history = "";
else
history = history.substring(0, lastComma);
}
UserPreferences.set("ServerDialog", "history", history);
UserPreferences.save("ServerDialog");

} catch (Exception e) {
Expand Down

0 comments on commit f4c9324

Please sign in to comment.