From 62a42ec8ca050326b42722fea9734973ed0ef1aa Mon Sep 17 00:00:00 2001 From: Joshua Duong Date: Thu, 30 Jul 2020 16:34:29 -0700 Subject: [adb] Correctly read host/user name on Windows. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug: 162111908 Test: On linux/mac: HOSTNAME="" adb keygen mykey; cat mykey.pub # Also LOGNAME HOSTNAME="测试" adb keygen mykey; cat mykey.pub HOSTNAME="test" adb keygen mykey; cat mykey.pub Test: On Windows: set COMPUTERNAME=&& adb keygen mykey && powershell -command "get-content -encoding utf8 mykey.pub" # Also USERNAME set COMPUTERNAME=测试&& adb keygen mykey && powershell -command "get-content -encoding utf8 mykey.pub" set COMPUTERNAME=test&& adb keygen mykey && powershell -command "get-content -encoding utf8 mykey.pub" Change-Id: I62c952c511a620286aa4e05b1763361406e9f89a --- adb/sysdeps_win32.cpp | 49 ------------------------------------------------- 1 file changed, 49 deletions(-) (limited to 'adb/sysdeps_win32.cpp') diff --git a/adb/sysdeps_win32.cpp b/adb/sysdeps_win32.cpp index be82bc0d1..217a6b7f8 100644 --- a/adb/sysdeps_win32.cpp +++ b/adb/sysdeps_win32.cpp @@ -1010,55 +1010,6 @@ int adb_register_socket(SOCKET s) { return _fh_to_int(f); } -static bool isBlankStr(const char* str) { - for (; *str != '\0'; ++str) { - if (!isblank(*str)) { - return false; - } - } - return true; -} - -int adb_gethostname(char* name, size_t len) { - const char* computerName = adb_getenv("COMPUTERNAME"); - if (computerName && !isBlankStr(computerName)) { - strncpy(name, computerName, len); - name[len - 1] = '\0'; - return 0; - } - - wchar_t buffer[MAX_COMPUTERNAME_LENGTH + 1]; - DWORD size = sizeof(buffer); - if (!GetComputerNameW(buffer, &size)) { - return -1; - } - std::string name_utf8; - if (!android::base::WideToUTF8(buffer, &name_utf8)) { - return -1; - } - - strncpy(name, name_utf8.c_str(), len); - name[len - 1] = '\0'; - return 0; -} - -int adb_getlogin_r(char* buf, size_t bufsize) { - wchar_t buffer[UNLEN + 1]; - DWORD len = sizeof(buffer); - if (!GetUserNameW(buffer, &len)) { - return -1; - } - - std::string login; - if (!android::base::WideToUTF8(buffer, &login)) { - return -1; - } - - strncpy(buf, login.c_str(), bufsize); - buf[bufsize - 1] = '\0'; - return 0; -} - #undef accept int adb_socket_accept(borrowed_fd serverfd, struct sockaddr* addr, socklen_t* addrlen) { FH serverfh = _fh_from_int(serverfd, __func__); -- cgit v1.2.3