Fix 'adb backup' command line validation
The host side wasn't properly checking for argument-list sufficiency
*after* removing any [-f filename] sequence.
Fixes bug 5164135
Change-Id: I7bc49e37ef168182088e0e664b6897dd2a088ebf
diff --git a/adb/commandline.c b/adb/commandline.c
index a69f867..75f337b 100644
--- a/adb/commandline.c
+++ b/adb/commandline.c
@@ -579,9 +579,6 @@
int fd, outFd;
int i, j;
- /* bare "adb backup" is not a valid command */
- if (argc < 2) return usage();
-
/* find, extract, and use any -f argument */
for (i = 1; i < argc; i++) {
if (!strcmp("-f", argv[i])) {
@@ -598,6 +595,9 @@
}
}
+ /* bare "adb backup" or "adb backup -f filename" are not valid invocations */
+ if (argc < 2) return usage();
+
outFd = adb_open_mode(filename, O_WRONLY | O_CREAT | O_TRUNC, 0640);
if (outFd < 0) {
fprintf(stderr, "adb: unable to open file %s\n", filename);