From f0a4fb6ea516e895ee6740cb192e7fa16f539892 Mon Sep 17 00:00:00 2001 From: Huihong Luo Date: Thu, 17 Aug 2017 15:23:08 -0700 Subject: [PATCH] Fix bug #37284906, adb shell crashes on windows with invalid options. For example, "adb.exe shell -list" crashes without this fix. Test: adb.exe shell -list-packages Bug: 67320882 Change-Id: I96be44128ff3ecab7804b70074cbde630b3fc3d1 (cherry picked from commit af39885c9fec7faeca393e2dc54ff8b4bba3ca6c) --- adb/commandline.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/adb/commandline.cpp b/adb/commandline.cpp index 9fac61cdd..9f234737b 100644 --- a/adb/commandline.cpp +++ b/adb/commandline.cpp @@ -686,6 +686,10 @@ static int adb_shell(int argc, const char** argv) { // Parse shell-specific command-line options. argv[0] = "adb shell"; // So getopt(3) error messages start "adb shell". +#ifdef _WIN32 + // fixes "adb shell -l" crash on Windows, b/37284906 + __argv = const_cast(argv); +#endif optind = 1; // argv[0] is always "shell", so set `optind` appropriately. int opt; while ((opt = getopt(argc, const_cast(argv), "+e:ntTx")) != -1) {