diff options
| author | 2022-12-13 22:48:20 +0000 | |
|---|---|---|
| committer | 2022-12-13 22:48:20 +0000 | |
| commit | d81f7b9331f33929944f995ef0ffec959678ca51 (patch) | |
| tree | 6a84fed79612522360b4730a6a94fe56ddbb285a | |
| parent | 27279606a7a43486f88ccab1d41fff3c15d7355a (diff) | |
| parent | 21f2a87ae50c1f4b3aa9bd5aa3d200b7cd41b4ba (diff) | |
Merge "Emulator: handle OOM and Protocol error cases" am: 940ca0c415 am: 21f2a87ae5
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2349603
Change-Id: Ib0603c763ce14ff265d35902957419bbf056a496
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
| -rw-r--r-- | services/core/java/com/android/server/clipboard/EmulatorClipboardMonitor.java | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/services/core/java/com/android/server/clipboard/EmulatorClipboardMonitor.java b/services/core/java/com/android/server/clipboard/EmulatorClipboardMonitor.java index ab3b2506f5ac..dce1c9684987 100644 --- a/services/core/java/com/android/server/clipboard/EmulatorClipboardMonitor.java +++ b/services/core/java/com/android/server/clipboard/EmulatorClipboardMonitor.java @@ -29,6 +29,7 @@ import android.util.Slog; import java.io.EOFException; import java.io.FileDescriptor; import java.io.InterruptedIOException; +import java.net.ProtocolException; import java.net.SocketException; import java.nio.ByteBuffer; import java.nio.ByteOrder; @@ -39,12 +40,16 @@ import java.util.function.Consumer; // write contents of the host system's clipboard. class EmulatorClipboardMonitor implements Consumer<ClipData> { private static final String TAG = "EmulatorClipboardMonitor"; + private static final String PIPE_NAME = "pipe:clipboard"; private static final int HOST_PORT = 5000; - private final Thread mHostMonitorThread; + private static final boolean LOG_CLIBOARD_ACCESS = SystemProperties.getBoolean("ro.boot.qemu.log_clipboard_access", false); + private static final int MAX_CLIPBOARD_BYTES = 128 << 20; + private FileDescriptor mPipe = null; + private final Thread mHostMonitorThread; private static byte[] createOpenHandshake() { // String.getBytes doesn't include the null terminator, @@ -97,8 +102,8 @@ class EmulatorClipboardMonitor implements Consumer<ClipData> { return fd; } - private static byte[] receiveMessage(final FileDescriptor fd) throws ErrnoException, - InterruptedIOException, EOFException { + private byte[] receiveMessage(final FileDescriptor fd) throws ErrnoException, + InterruptedIOException, EOFException, ProtocolException { final byte[] lengthBits = new byte[4]; readFully(fd, lengthBits, 0, lengthBits.length); @@ -106,6 +111,10 @@ class EmulatorClipboardMonitor implements Consumer<ClipData> { bb.order(ByteOrder.LITTLE_ENDIAN); final int msgLen = bb.getInt(); + if (msgLen <= 0 || msgLen > MAX_CLIPBOARD_BYTES) { + throw new ProtocolException("Clipboard message length: " + msgLen + " out of bounds."); + } + final byte[] msg = new byte[msgLen]; readFully(fd, msg, 0, msg.length); @@ -150,7 +159,8 @@ class EmulatorClipboardMonitor implements Consumer<ClipData> { } setAndroidClipboard.accept(clip); } catch (ErrnoException | EOFException | InterruptedIOException - | InterruptedException e) { + | InterruptedException | ProtocolException | OutOfMemoryError e) { + Slog.w(TAG, "Failure to read from host clipboard", e); setPipeFD(null); try { |