am 0df24ea2: Merge "adb: refactor _is_valid_ack_reply_fd"
* commit '0df24ea234fcfb9ac57ed94701868426a41d8642': adb: refactor _is_valid_ack_reply_fd
This commit is contained in:
commit
bd9305eeb7
1 changed files with 13 additions and 8 deletions
|
|
@ -939,6 +939,18 @@ static int adb_query_command(const std::string& command) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Disallow stdin, stdout, and stderr.
|
||||||
|
static bool _is_valid_ack_reply_fd(const int ack_reply_fd) {
|
||||||
|
#ifdef _WIN32
|
||||||
|
const HANDLE ack_reply_handle = cast_int_to_handle(ack_reply_fd);
|
||||||
|
return (GetStdHandle(STD_INPUT_HANDLE) != ack_reply_handle) &&
|
||||||
|
(GetStdHandle(STD_OUTPUT_HANDLE) != ack_reply_handle) &&
|
||||||
|
(GetStdHandle(STD_ERROR_HANDLE) != ack_reply_handle);
|
||||||
|
#else
|
||||||
|
return ack_reply_fd > 2;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
int adb_commandline(int argc, const char **argv) {
|
int adb_commandline(int argc, const char **argv) {
|
||||||
int no_daemon = 0;
|
int no_daemon = 0;
|
||||||
int is_daemon = 0;
|
int is_daemon = 0;
|
||||||
|
|
@ -988,14 +1000,7 @@ int adb_commandline(int argc, const char **argv) {
|
||||||
argc--;
|
argc--;
|
||||||
argv++;
|
argv++;
|
||||||
ack_reply_fd = strtol(reply_fd_str, nullptr, 10);
|
ack_reply_fd = strtol(reply_fd_str, nullptr, 10);
|
||||||
#ifdef _WIN32
|
if (!_is_valid_ack_reply_fd(ack_reply_fd)) {
|
||||||
const HANDLE ack_reply_handle = cast_int_to_handle(ack_reply_fd);
|
|
||||||
if ((GetStdHandle(STD_INPUT_HANDLE) == ack_reply_handle) ||
|
|
||||||
(GetStdHandle(STD_OUTPUT_HANDLE) == ack_reply_handle) ||
|
|
||||||
(GetStdHandle(STD_ERROR_HANDLE) == ack_reply_handle)) {
|
|
||||||
#else
|
|
||||||
if (ack_reply_fd <= 2) { // Disallow stdin, stdout, and stderr.
|
|
||||||
#endif
|
|
||||||
fprintf(stderr, "adb: invalid reply fd \"%s\"\n", reply_fd_str);
|
fprintf(stderr, "adb: invalid reply fd \"%s\"\n", reply_fd_str);
|
||||||
return usage();
|
return usage();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue