diff options
| author | Narayan Kamath <narayan@google.com> | 2016-08-18 10:25:53 +0000 |
|---|---|---|
| committer | android-build-merger <android-build-merger@google.com> | 2016-08-18 10:25:53 +0000 |
| commit | 156720056ba334a2b0127e3a2ebafa612ecfe6c2 (patch) | |
| tree | 08b442da8f222b9d3a5e355022e6ea90f6d96c8e /core/java/android/os/Process.java | |
| parent | 185aff8565d3503fe5dd102a5e25120bc381b9f0 (diff) | |
| parent | 6bc7670c67ba8f9717e8bb0af6f7256a2d83a0a5 (diff) | |
Process: Fix communication with zygote. am: 448be0a622
am: 6bc7670c67
Change-Id: I37ea2a3324277340fce69fcc6a5101bee0637dca
Diffstat (limited to 'core/java/android/os/Process.java')
| -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 4ef882e1aa78..e1b7fdad25e7 100644 --- a/core/java/android/os/Process.java +++ b/core/java/android/os/Process.java @@ -567,6 +567,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: @@ -583,13 +592,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(); } @@ -598,11 +602,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(); |
