Revision: 5138 http://sourceforge.net/p/tigervnc/code/5138 Author: bphinz Date: 2013-11-23 05:05:21 +0000 (Sat, 23 Nov 2013) Log Message: ----------- Fixes a condition where too much data on the local clipboard causes the client to exceed the max heap size and exit. Since the server will, by default, discard clipboard transfers greater than 256KB anyway, a parameter was added which sets the default max clipboard size that the client will hold to 256KB also.
Modified Paths: -------------- trunk/java/com/tigervnc/vncviewer/ClipboardDialog.java trunk/java/com/tigervnc/vncviewer/DesktopWindow.java trunk/java/com/tigervnc/vncviewer/VncViewer.java Modified: trunk/java/com/tigervnc/vncviewer/ClipboardDialog.java =================================================================== --- trunk/java/com/tigervnc/vncviewer/ClipboardDialog.java 2013-11-06 15:27:04 UTC (rev 5137) +++ trunk/java/com/tigervnc/vncviewer/ClipboardDialog.java 2013-11-23 05:05:21 UTC (rev 5138) @@ -57,17 +57,14 @@ pack(); } - public void initDialog() { - textArea.setText(current); - textArea.selectAll(); - } - public void setContents(String str) { - current = str; textArea.setText(str); - textArea.selectAll(); } + public String getContents() { + return textArea.getText(); + } + public void serverCutText(String str, int len) { setContents(str); SecurityManager sm = System.getSecurityManager(); @@ -77,13 +74,13 @@ if (cb != null) { StringSelection ss = new StringSelection(str); try { - cb.setContents(ss, ss); + cb.setContents(ss, null); } catch(Exception e) { - vlog.debug(e.toString()); + vlog.debug(e.getMessage()); } } } catch(SecurityException e) { - System.err.println("Cannot access the system clipboard"); + vlog.debug("Cannot access the system clipboard: "+e.getMessage()); } } @@ -94,11 +91,9 @@ public void actionPerformed(ActionEvent e) { Object s = e.getSource(); if (s instanceof JButton && (JButton)s == clearButton) { - current = ""; - textArea.setText(current); + serverCutText(new String(""), 0); } else if (s instanceof JButton && (JButton)s == sendButton) { - current = textArea.getText(); - cc.writeClientCutText(current, current.length()); + cc.writeClientCutText(textArea.getText(), textArea.getText().length()); endDialog(); } else if (s instanceof JButton && (JButton)s == cancelButton) { endDialog(); @@ -106,7 +101,6 @@ } CConn cc; - String current; JTextArea textArea; JButton clearButton, sendButton, cancelButton; static LogWriter vlog = new LogWriter("ClipboardDialog"); Modified: trunk/java/com/tigervnc/vncviewer/DesktopWindow.java =================================================================== --- trunk/java/com/tigervnc/vncviewer/DesktopWindow.java 2013-11-06 15:27:04 UTC (rev 5137) +++ trunk/java/com/tigervnc/vncviewer/DesktopWindow.java 2013-11-23 05:05:21 UTC (rev 5138) @@ -357,30 +357,33 @@ g2.dispose(); } - String oldContents = ""; - public synchronized void checkClipboard() { SecurityManager sm = System.getSecurityManager(); try { if (sm != null) sm.checkSystemClipboardAccess(); Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard(); - if (cb != null && cc.viewer.sendClipboard.getValue()) { - Transferable t = cb.getContents(null); - if ((t != null) && t.isDataFlavorSupported(DataFlavor.stringFlavor)) { - try { - String newContents = (String)t.getTransferData(DataFlavor.stringFlavor); - if (newContents != null && !newContents.equals(oldContents)) { + if (cb == null) return; + Transferable t = cb.getContents(null); + if ((t != null) && t.isDataFlavorSupported(DataFlavor.stringFlavor)) { + try { + String newContents = new String(""); + if (t.getTransferData(DataFlavor.stringFlavor) != null) { + int len = Math.min(cc.viewer.maxCutText.getValue(), + ((String)t.getTransferData(DataFlavor.stringFlavor)).length()); + newContents = + ((String)t.getTransferData(DataFlavor.stringFlavor)).substring(0, len); + } + if (!newContents.equals(cc.clipboardDialog.getContents())) { + if (cc.viewer.sendClipboard.getValue()) cc.writeClientCutText(newContents, newContents.length()); - oldContents = newContents; - cc.clipboardDialog.setContents(newContents); - } - } catch(java.lang.Exception e) { - System.out.println("Exception getting clipboard data: " + e.getMessage()); + cc.clipboardDialog.setContents(newContents); } + } catch(java.lang.Exception e) { + vlog.debug("Exception getting clipboard data: " + e.getMessage()); } } } catch(SecurityException e) { - System.err.println("Cannot access the system clipboard"); + vlog.debug("Cannot access the system clipboard"); } } Modified: trunk/java/com/tigervnc/vncviewer/VncViewer.java =================================================================== --- trunk/java/com/tigervnc/vncviewer/VncViewer.java 2013-11-06 15:27:04 UTC (rev 5137) +++ trunk/java/com/tigervnc/vncviewer/VncViewer.java 2013-11-23 05:05:21 UTC (rev 5138) @@ -460,6 +460,10 @@ = new BoolParameter("SendClipboard", "Send clipboard changes to the server", true); + IntParameter maxCutText + = new IntParameter("MaxCutText", + "Maximum permitted length of an outgoing clipboard update", + 262144); StringParameter menuKey = new StringParameter("MenuKey", "The key which brings up the popup menu", This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Shape the Mobile Experience: Free Subscription Software experts and developers: Be at the forefront of tech innovation. Intel(R) Software Adrenaline delivers strategic insight and game-changing conversations that shape the rapidly evolving mobile landscape. Sign up now. http://pubads.g.doubleclick.net/gampad/clk?id=63431311&iu=/4140/ostg.clktrk _______________________________________________ Tigervnc-commits mailing list Tigervnc-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/tigervnc-commits