summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author David Christie <dnchrist@google.com> 2016-08-24 22:43:09 +0000
committer android-build-merger <android-build-merger@google.com> 2016-08-24 22:43:09 +0000
commit7f2aaf204da6d1e328e36c99b5a7758519cc32f4 (patch)
treec1650dd37e4fce9ffa7595930f8c701dac4f69d6
parent00e1e39ae2ee27bb533b57adc90038fb46683fc6 (diff)
parent187d841b75d8096ee1ef4b31e4a2ba947248f887 (diff)
resolve merge conflicts of b4a5615 to lmp-dev am: 288166cbb2 am: b7f8b59e24 am: 41a0dd41f1 am: af369f6e66 am: d610363a48 am: 0777ad8253
am: 187d841b75 Change-Id: I063f0cd3f53be4d58d123d05da7171a47014929d
-rw-r--r--core/java/android/os/Process.java21
1 files changed, 15 insertions, 6 deletions
diff --git a/core/java/android/os/Process.java b/core/java/android/os/Process.java
index 7234e985757a..e0a0fd0c9791 100644
--- a/core/java/android/os/Process.java
+++ b/core/java/android/os/Process.java
@@ -538,6 +538,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:
@@ -554,13 +563,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();
}
@@ -569,11 +573,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();