Skip to content

Commit a34c9ca

Browse files
krutonandroid-build SharedAccount
authored andcommitted
Add more error checking for ndc
In NativeDaemonConnector.doCommand() calls, there was inconsistent error checking. This change adds error checking for every call and makes it so that any call to .doCommand() that gets an error code won't cause the code to hang forever. Change-Id: If714282b6642f278fb8137f652af1a012670253b
1 parent 24a0308 commit a34c9ca

File tree

3 files changed

+280
-113
lines changed

3 files changed

+280
-113
lines changed

services/java/com/android/server/MountService.java

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -642,10 +642,20 @@ private void notifyVolumeStateChange(String label, String path, int oldState, in
642642
}
643643

644644
private boolean doGetShareMethodAvailable(String method) {
645-
ArrayList<String> rsp = mConnector.doCommand("share status " + method);
645+
try {
646+
ArrayList<String> rsp = mConnector.doCommand("share status " + method);
647+
} catch (NativeDaemonConnectorException ex) {
648+
Slog.e(TAG, "Failed to determine whether share method " + method + " is available.");
649+
return false;
650+
}
646651

647652
for (String line : rsp) {
648-
String []tok = line.split(" ");
653+
String[] tok = line.split(" ");
654+
if (tok.length < 3) {
655+
Slog.e(TAG, "Malformed response to share status " + method);
656+
return false;
657+
}
658+
649659
int code;
650660
try {
651661
code = Integer.parseInt(tok[0]);
@@ -770,10 +780,22 @@ private int doFormatVolume(String path) {
770780

771781
private boolean doGetVolumeShared(String path, String method) {
772782
String cmd = String.format("volume shared %s %s", path, method);
773-
ArrayList<String> rsp = mConnector.doCommand(cmd);
783+
ArrayList<String> rsp;
784+
785+
try {
786+
rsp = mConnector.doCommand(cmd);
787+
} catch (NativeDaemonConnectorException ex) {
788+
Slog.e(TAG, "Failed to read response to volume shared " + path + " " + method);
789+
return false;
790+
}
774791

775792
for (String line : rsp) {
776-
String []tok = line.split(" ");
793+
String[] tok = line.split(" ");
794+
if (tok.length < 3) {
795+
Slog.e(TAG, "Malformed response to volume shared " + path + " " + method + " command");
796+
return false;
797+
}
798+
777799
int code;
778800
try {
779801
code = Integer.parseInt(tok[0]);
@@ -782,9 +804,7 @@ private boolean doGetVolumeShared(String path, String method) {
782804
return false;
783805
}
784806
if (code == VoldResponseCode.ShareEnabledResult) {
785-
if (tok[2].equals("enabled"))
786-
return true;
787-
return false;
807+
return "enabled".equals(tok[2]);
788808
} else {
789809
Slog.e(TAG, String.format("Unexpected response code %d", code));
790810
return false;

services/java/com/android/server/NativeDaemonConnector.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,11 @@ private void listenToSocket() throws IOException {
128128
Slog.e(TAG, String.format(
129129
"Error handling '%s'", event), ex);
130130
}
131-
} else {
132-
try {
133-
mResponseQueue.put(event);
134-
} catch (InterruptedException ex) {
135-
Slog.e(TAG, "Failed to put response onto queue", ex);
136-
}
131+
}
132+
try {
133+
mResponseQueue.put(event);
134+
} catch (InterruptedException ex) {
135+
Slog.e(TAG, "Failed to put response onto queue", ex);
137136
}
138137
} catch (NumberFormatException nfe) {
139138
Slog.w(TAG, String.format("Bad msg (%s)", event));

0 commit comments

Comments
 (0)