diff options
| author | 2016-08-18 09:58:45 +0000 | |
|---|---|---|
| committer | 2016-08-18 09:58:45 +0000 | |
| commit | 8788a2413c52b83d07f3c7bd71eb8ca6c16e5b7f (patch) | |
| tree | f829996924c6867e28ff5e5f75521037c8e536ba | |
| parent | 41a0dd41f179791468943b103e44ad578f789b69 (diff) | |
| parent | 1bd43c162ff9950be639729ded132d1262827e54 (diff) | |
Process: Fix communication with zygote. am: e29c6493c0
am: 1bd43c162f
Change-Id: Ic38c43db48584b3d899e120fd65a4058d806a39f
| -rw-r--r-- | core/java/android/os/Process.java | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/core/java/android/os/Process.java b/core/java/android/os/Process.java index 21a990421e59..10297317e524 100644 --- a/core/java/android/os/Process.java +++ b/core/java/android/os/Process.java @@ -537,6 +537,15 @@ public class Process { ZygoteState zygoteState, ArrayList<String> args) throws ZygoteStartFailedEx { try { + // Throw early if any of the arguments are malformed. This means we can + // avoid writing a partial response to the zygote. + int sz = args.size(); + for (int i = 0; i < sz; i++) { + if (args.get(i).indexOf('\n') >= 0) { + throw new ZygoteStartFailedEx("embedded newlines not allowed"); + } + } + /** * See com.android.internal.os.ZygoteInit.readArgumentList() * Presently the wire format to the zygote process is: @@ -553,13 +562,8 @@ public class Process { writer.write(Integer.toString(args.size())); writer.newLine(); - int sz = args.size(); for (int i = 0; i < sz; i++) { String arg = args.get(i); - if (arg.indexOf('\n') >= 0) { - throw new ZygoteStartFailedEx( - "embedded newlines not allowed"); - } writer.write(arg); writer.newLine(); } @@ -568,11 +572,16 @@ public class Process { // Should there be a timeout on this? ProcessStartResult result = new ProcessStartResult(); + + // Always read the entire result from the input stream to avoid leaving + // bytes in the stream for future process starts to accidentally stumble + // upon. result.pid = inputStream.readInt(); + result.usingWrapper = inputStream.readBoolean(); + if (result.pid < 0) { throw new ZygoteStartFailedEx("fork() failed"); } - result.usingWrapper = inputStream.readBoolean(); return result; } catch (IOException ex) { zygoteState.close(); |