summaryrefslogtreecommitdiff
path: root/core/java/android
diff options
context:
space:
mode:
authorNarayan Kamath <narayan@google.com>2016-08-18 09:56:24 +0000
committerandroid-build-merger <android-build-merger@google.com>2016-08-18 09:56:24 +0000
commitb56f4f53e1ecf552ca91744d488ac599e5f29e99 (patch)
tree3b375ad014e945b807bb307bc3b65d067f71adb1 /core/java/android
parent5a6b11114a64f8dd219325c359006a682c62bf57 (diff)
parentb85e9e9108976122f2c4cf08d606c05b960bc5d4 (diff)
Process: Fix communication with zygote. am: 8e69dd2284
am: b85e9e9108 Change-Id: Ie4874c088e05f4f5bc2073661010d413e60b3f7b
Diffstat (limited to 'core/java/android')
-rw-r--r--core/java/android/os/Process.java20
1 files changed, 14 insertions, 6 deletions
diff --git a/core/java/android/os/Process.java b/core/java/android/os/Process.java
index 057f516af17b..6227511387d1 100644
--- a/core/java/android/os/Process.java
+++ b/core/java/android/os/Process.java
@@ -495,6 +495,15 @@ public class Process {
openZygoteSocketIfNeeded();
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:
@@ -509,13 +518,8 @@ public class Process {
sZygoteWriter.write(Integer.toString(args.size()));
sZygoteWriter.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");
- }
sZygoteWriter.write(arg);
sZygoteWriter.newLine();
}
@@ -524,11 +528,15 @@ 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 = sZygoteInputStream.readInt();
+ result.usingWrapper = sZygoteInputStream.readBoolean();
+
if (result.pid < 0) {
throw new ZygoteStartFailedEx("fork() failed");
}
- result.usingWrapper = sZygoteInputStream.readBoolean();
return result;
} catch (IOException ex) {
try {