am 81fa3039
: Merge "Remove yet more fixed-length buffers (and their overruns)."
* commit '81fa3039fa7b5c6a18747cf5bdac32a1c6091427': Remove yet more fixed-length buffers (and their overruns).
This commit is contained in:
commit
613584a24b
6 changed files with 27 additions and 90 deletions
|
@ -383,7 +383,7 @@ int main(int argc, char **argv) {
|
|||
/* If adbd runs inside the emulator this will enable adb tracing via
|
||||
* adb-debug qemud service in the emulator. */
|
||||
adb_qemu_trace_init();
|
||||
while (1) {
|
||||
while (true) {
|
||||
int c;
|
||||
int option_index = 0;
|
||||
static struct option opts[] = {
|
||||
|
|
|
@ -16,10 +16,18 @@
|
|||
|
||||
#include "adb_utils.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
bool getcwd(std::string* s) {
|
||||
char* cwd = getcwd(nullptr, 0);
|
||||
if (cwd != nullptr) *s = cwd;
|
||||
free(cwd);
|
||||
return (cwd != nullptr);
|
||||
}
|
||||
|
||||
bool directory_exists(const std::string& path) {
|
||||
struct stat sb;
|
||||
return lstat(path.c_str(), &sb) != -1 && S_ISDIR(sb.st_mode);
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
#include <string>
|
||||
|
||||
bool getcwd(std::string* cwd);
|
||||
bool directory_exists(const std::string& path);
|
||||
|
||||
std::string escape_arg(const std::string& s);
|
||||
|
|
|
@ -321,7 +321,7 @@ static void copy_to_file(int inFd, int outFd) {
|
|||
stdin_raw_init(STDIN_FILENO);
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
while (true) {
|
||||
if (inFd == STDIN_FILENO) {
|
||||
len = unix_read(inFd, buf, BUFSIZE);
|
||||
} else {
|
||||
|
@ -554,7 +554,7 @@ static int adb_sideload_host(const char* fn) {
|
|||
|
||||
opt = adb_setsockopt(fd, SOL_SOCKET, SO_SNDBUF, (const void *) &opt, sizeof(opt));
|
||||
|
||||
for (;;) {
|
||||
while (true) {
|
||||
if (!ReadFdExactly(fd, buf, 8)) {
|
||||
fprintf(stderr, "* failed to read command: %s\n", adb_error());
|
||||
status = -1;
|
||||
|
@ -872,81 +872,9 @@ static int restore(int argc, const char** argv) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
#define SENTINEL_FILE "config" OS_PATH_SEPARATOR_STR "envsetup.make"
|
||||
static int top_works(const char *top)
|
||||
{
|
||||
if (top != NULL && adb_is_absolute_host_path(top)) {
|
||||
char path_buf[PATH_MAX];
|
||||
snprintf(path_buf, sizeof(path_buf),
|
||||
"%s" OS_PATH_SEPARATOR_STR SENTINEL_FILE, top);
|
||||
return access(path_buf, F_OK) == 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static char *find_top_from(const char *indir, char path_buf[PATH_MAX])
|
||||
{
|
||||
strcpy(path_buf, indir);
|
||||
while (1) {
|
||||
if (top_works(path_buf)) {
|
||||
return path_buf;
|
||||
}
|
||||
char *s = adb_dirstop(path_buf);
|
||||
if (s != NULL) {
|
||||
*s = '\0';
|
||||
} else {
|
||||
path_buf[0] = '\0';
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static char *find_top(char path_buf[PATH_MAX])
|
||||
{
|
||||
char *top = getenv("ANDROID_BUILD_TOP");
|
||||
if (top != NULL && top[0] != '\0') {
|
||||
if (!top_works(top)) {
|
||||
fprintf(stderr, "adb: bad ANDROID_BUILD_TOP value \"%s\"\n", top);
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
top = getenv("TOP");
|
||||
if (top != NULL && top[0] != '\0') {
|
||||
if (!top_works(top)) {
|
||||
fprintf(stderr, "adb: bad TOP value \"%s\"\n", top);
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
top = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (top != NULL) {
|
||||
/* The environment pointed to a top directory that works.
|
||||
*/
|
||||
strcpy(path_buf, top);
|
||||
return path_buf;
|
||||
}
|
||||
|
||||
/* The environment didn't help. Walk up the tree from the CWD
|
||||
* to see if we can find the top.
|
||||
*/
|
||||
char dir[PATH_MAX];
|
||||
top = find_top_from(getcwd(dir, sizeof(dir)), path_buf);
|
||||
if (top == NULL) {
|
||||
/* If the CWD isn't under a good-looking top, see if the
|
||||
* executable is.
|
||||
*/
|
||||
get_my_path(dir, PATH_MAX);
|
||||
top = find_top_from(dir, path_buf);
|
||||
}
|
||||
return top;
|
||||
}
|
||||
|
||||
/* <hint> may be:
|
||||
* - A simple product name
|
||||
* e.g., "sooner"
|
||||
TODO: debug? sooner-debug, sooner:debug?
|
||||
* - A relative path from the CWD to the ANDROID_PRODUCT_OUT dir
|
||||
* e.g., "out/target/product/sooner"
|
||||
* - An absolute path to the PRODUCT_OUT dir
|
||||
|
@ -967,26 +895,26 @@ static std::string find_product_out_path(const char* hint) {
|
|||
|
||||
// If there are any slashes in it, assume it's a relative path;
|
||||
// make it absolute.
|
||||
if (adb_dirstart(hint) != NULL) {
|
||||
char cwd[PATH_MAX];
|
||||
if (getcwd(cwd, sizeof(cwd)) == NULL) {
|
||||
fprintf(stderr, "adb: Couldn't get CWD: %s\n", strerror(errno));
|
||||
if (adb_dirstart(hint) != nullptr) {
|
||||
std::string cwd;
|
||||
if (!getcwd(&cwd)) {
|
||||
fprintf(stderr, "adb: getcwd failed: %s\n", strerror(errno));
|
||||
return "";
|
||||
}
|
||||
return android::base::StringPrintf("%s%s%s", cwd, OS_PATH_SEPARATOR_STR, hint);
|
||||
return android::base::StringPrintf("%s%s%s", cwd.c_str(), OS_PATH_SEPARATOR_STR, hint);
|
||||
}
|
||||
|
||||
// It's a string without any slashes. Try to do something with it.
|
||||
//
|
||||
// Try to find the root of the build tree, and build a PRODUCT_OUT
|
||||
// path from there.
|
||||
char top_buf[PATH_MAX];
|
||||
const char* top = find_top(top_buf);
|
||||
char* top = getenv("ANDROID_BUILD_TOP");
|
||||
if (top == nullptr) {
|
||||
fprintf(stderr, "adb: Couldn't find top of build tree\n");
|
||||
fprintf(stderr, "adb: ANDROID_BUILD_TOP not set!\n");
|
||||
return "";
|
||||
}
|
||||
std::string path = top_buf;
|
||||
|
||||
std::string path = top;
|
||||
path += OS_PATH_SEPARATOR_STR;
|
||||
path += "out";
|
||||
path += OS_PATH_SEPARATOR_STR;
|
||||
|
@ -998,7 +926,7 @@ static std::string find_product_out_path(const char* hint) {
|
|||
if (!directory_exists(path)) {
|
||||
fprintf(stderr, "adb: Couldn't find a product dir based on -p %s; "
|
||||
"\"%s\" doesn't exist\n", hint, path.c_str());
|
||||
return NULL;
|
||||
return "";
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
|
|
@ -192,7 +192,7 @@ void reboot_service(int fd, void* arg)
|
|||
if (reboot_service_impl(fd, static_cast<const char*>(arg))) {
|
||||
// Don't return early. Give the reboot command time to take effect
|
||||
// to avoid messing up scripts which do "adb reboot && adb wait-for-device"
|
||||
while (1) {
|
||||
while (true) {
|
||||
pause();
|
||||
}
|
||||
}
|
||||
|
@ -373,7 +373,7 @@ static void subproc_waiter_service(int fd, void *cookie)
|
|||
pid_t pid = (pid_t) (uintptr_t) cookie;
|
||||
|
||||
D("entered. fd=%d of pid=%d\n", fd, pid);
|
||||
for (;;) {
|
||||
while (true) {
|
||||
int status;
|
||||
pid_t p = waitpid(pid, &status, 0);
|
||||
if (p == pid) {
|
||||
|
|
|
@ -163,7 +163,7 @@ static void *usb_adb_open_thread(void *x)
|
|||
struct usb_handle *usb = (struct usb_handle *)x;
|
||||
int fd;
|
||||
|
||||
while (1) {
|
||||
while (true) {
|
||||
// wait until the USB device needs opening
|
||||
adb_mutex_lock(&usb->lock);
|
||||
while (usb->fd != -1)
|
||||
|
@ -347,14 +347,14 @@ static void *usb_ffs_open_thread(void *x)
|
|||
{
|
||||
struct usb_handle *usb = (struct usb_handle *)x;
|
||||
|
||||
while (1) {
|
||||
while (true) {
|
||||
// wait until the USB device needs opening
|
||||
adb_mutex_lock(&usb->lock);
|
||||
while (usb->control != -1 && usb->bulk_in != -1 && usb->bulk_out != -1)
|
||||
adb_cond_wait(&usb->notify, &usb->lock);
|
||||
adb_mutex_unlock(&usb->lock);
|
||||
|
||||
while (1) {
|
||||
while (true) {
|
||||
init_functionfs(usb);
|
||||
|
||||
if (usb->control >= 0 && usb->bulk_in >= 0 && usb->bulk_out >= 0)
|
||||
|
|
Loading…
Reference in a new issue