vold: Fix argument validation for volume commands
Change-Id: I74aa63ff9f9bc32bd871e6c53ab50b6baf79e650
Signed-off-by: San Mehat <san@google.com>
diff --git a/CommandListener.cpp b/CommandListener.cpp
index b66f7cb..72794ae 100644
--- a/CommandListener.cpp
+++ b/CommandListener.cpp
@@ -113,23 +113,55 @@
if (!strcmp(argv[1], "list")) {
return vm->listVolumes(cli);
} else if (!strcmp(argv[1], "debug")) {
- vm->setDebug(true);
+ if (argc != 3 || (argc == 3 && (strcmp(argv[2], "off") && strcmp(argv[2], "on")))) {
+ cli->sendMsg(ResponseCode::CommandSyntaxError, "Usage: volume debug <off/on>", false);
+ return 0;
+ }
+ vm->setDebug(!strcmp(argv[2], "on") ? true : false);
} else if (!strcmp(argv[1], "mount")) {
+ if (argc != 3) {
+ cli->sendMsg(ResponseCode::CommandSyntaxError, "Usage: volume mount <path>", false);
+ return 0;
+ }
rc = vm->mountVolume(argv[2]);
} else if (!strcmp(argv[1], "unmount")) {
+ if (argc < 3 || argc > 4 || (argc == 4 && strcmp(argv[3], "force"))) {
+ cli->sendMsg(ResponseCode::CommandSyntaxError, "Usage: volume unmount <path> [force]", false);
+ return 0;
+ }
+
bool force = false;
if (argc >= 4 && !strcmp(argv[3], "force")) {
force = true;
}
rc = vm->unmountVolume(argv[2], force);
} else if (!strcmp(argv[1], "format")) {
+ if (argc != 3) {
+ cli->sendMsg(ResponseCode::CommandSyntaxError, "Usage: volume format <path>", false);
+ return 0;
+ }
rc = vm->formatVolume(argv[2]);
} else if (!strcmp(argv[1], "share")) {
+ if (argc != 4) {
+ cli->sendMsg(ResponseCode::CommandSyntaxError,
+ "Usage: volume share <path> <method>", false);
+ return 0;
+ }
rc = vm->shareVolume(argv[2], argv[3]);
} else if (!strcmp(argv[1], "unshare")) {
+ if (argc != 4) {
+ cli->sendMsg(ResponseCode::CommandSyntaxError,
+ "Usage: volume unshare <path> <method>", false);
+ return 0;
+ }
rc = vm->unshareVolume(argv[2], argv[3]);
} else if (!strcmp(argv[1], "shared")) {
bool enabled = false;
+ if (argc != 4) {
+ cli->sendMsg(ResponseCode::CommandSyntaxError,
+ "Usage: volume shared <path> <method>", false);
+ return 0;
+ }
if (vm->shareEnabled(argv[2], argv[3], &enabled)) {
cli->sendMsg(