Merge "Revert "Turn on -Wformat-nonliteral.""
This commit is contained in:
commit
e84205bf6e
11 changed files with 72 additions and 83 deletions
|
|
@ -15,9 +15,8 @@ adb_version := $(shell git -C $(LOCAL_PATH) rev-parse --short=12 HEAD 2>/dev/nul
|
||||||
|
|
||||||
ADB_COMMON_CFLAGS := \
|
ADB_COMMON_CFLAGS := \
|
||||||
-Wall -Wextra -Werror \
|
-Wall -Wextra -Werror \
|
||||||
-Wformat-nonliteral \
|
|
||||||
-Wno-missing-field-initializers \
|
|
||||||
-Wno-unused-parameter \
|
-Wno-unused-parameter \
|
||||||
|
-Wno-missing-field-initializers \
|
||||||
-DADB_REVISION='"$(adb_version)"' \
|
-DADB_REVISION='"$(adb_version)"' \
|
||||||
|
|
||||||
# libadb
|
# libadb
|
||||||
|
|
|
||||||
|
|
@ -277,8 +277,8 @@ asocket *create_remote_socket(unsigned id, atransport *t);
|
||||||
void connect_to_remote(asocket *s, const char *destination);
|
void connect_to_remote(asocket *s, const char *destination);
|
||||||
void connect_to_smartsocket(asocket *s);
|
void connect_to_smartsocket(asocket *s);
|
||||||
|
|
||||||
void fatal(const char *fmt, ...) ATTRIBUTE_FORMAT(1, 2);
|
void fatal(const char *fmt, ...);
|
||||||
void fatal_errno(const char *fmt, ...) ATTRIBUTE_FORMAT(1, 2);
|
void fatal_errno(const char *fmt, ...);
|
||||||
|
|
||||||
void handle_packet(apacket *p, atransport *t);
|
void handle_packet(apacket *p, atransport *t);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,6 @@
|
||||||
#include "mincrypt/rsa.h"
|
#include "mincrypt/rsa.h"
|
||||||
#undef RSA_verify
|
#undef RSA_verify
|
||||||
|
|
||||||
#include <base/logging.h>
|
|
||||||
#include <base/strings.h>
|
#include <base/strings.h>
|
||||||
#include <cutils/list.h>
|
#include <cutils/list.h>
|
||||||
|
|
||||||
|
|
@ -57,10 +56,8 @@
|
||||||
#include <openssl/base64.h>
|
#include <openssl/base64.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "adb_utils.h"
|
#define ANDROID_PATH ".android"
|
||||||
|
#define ADB_KEY_FILE "adbkey"
|
||||||
const char kAndroidPath[] = ".android";
|
|
||||||
const char kAdbKeyFile[] = "adbkey";
|
|
||||||
|
|
||||||
struct adb_private_key {
|
struct adb_private_key {
|
||||||
struct listnode node;
|
struct listnode node;
|
||||||
|
|
@ -298,58 +295,64 @@ static int read_key(const char *file, struct listnode *list)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool get_user_keyfilepath(std::string* filename) {
|
static int get_user_keyfilepath(char *filename, size_t len)
|
||||||
CHECK(filename != nullptr);
|
{
|
||||||
|
const char *format, *home;
|
||||||
|
char android_dir[PATH_MAX];
|
||||||
|
struct stat buf;
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
const char* home = getenv("ANDROID_SDK_HOME");
|
char path[PATH_MAX];
|
||||||
if (home == nullptr) {
|
home = getenv("ANDROID_SDK_HOME");
|
||||||
char path[PATH_MAX];
|
if (!home) {
|
||||||
SHGetFolderPath(NULL, CSIDL_PROFILE, NULL, 0, path);
|
SHGetFolderPath(NULL, CSIDL_PROFILE, NULL, 0, path);
|
||||||
home = path;
|
home = path;
|
||||||
}
|
}
|
||||||
|
format = "%s\\%s";
|
||||||
#else
|
#else
|
||||||
const char* home = getenv("HOME");
|
home = getenv("HOME");
|
||||||
if (home == nullptr)
|
if (!home)
|
||||||
return false;
|
return -1;
|
||||||
|
format = "%s/%s";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
D("home '%s'\n", home);
|
D("home '%s'\n", home);
|
||||||
|
|
||||||
const std::string android_dir = android::base::Join(
|
if (snprintf(android_dir, sizeof(android_dir), format, home,
|
||||||
std::vector<std::string>({home, kAndroidPath}), OS_PATH_SEPARATOR);
|
ANDROID_PATH) >= (int)sizeof(android_dir))
|
||||||
|
return -1;
|
||||||
|
|
||||||
if (!directory_exists(android_dir)) {
|
if (stat(android_dir, &buf)) {
|
||||||
if (adb_mkdir(android_dir.c_str(), 0750) == -1) {
|
if (adb_mkdir(android_dir, 0750) < 0) {
|
||||||
D("Cannot mkdir '%s'", android_dir.c_str());
|
D("Cannot mkdir '%s'", android_dir);
|
||||||
return false;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
*filename = android::base::Join(
|
return snprintf(filename, len, format, android_dir, ADB_KEY_FILE);
|
||||||
std::vector<std::string>({android_dir, kAdbKeyFile}),
|
|
||||||
OS_PATH_SEPARATOR);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int get_user_key(struct listnode *list)
|
static int get_user_key(struct listnode *list)
|
||||||
{
|
{
|
||||||
std::string path;
|
struct stat buf;
|
||||||
if (!get_user_keyfilepath(&path)) {
|
char path[PATH_MAX];
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
ret = get_user_keyfilepath(path, sizeof(path));
|
||||||
|
if (ret < 0 || ret >= (signed)sizeof(path)) {
|
||||||
D("Error getting user key filename");
|
D("Error getting user key filename");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
D("user key '%s'\n", path.c_str());
|
D("user key '%s'\n", path);
|
||||||
|
|
||||||
if (!file_exists(path)) {
|
if (stat(path, &buf) == -1) {
|
||||||
if (!generate_key(path.c_str())) {
|
if (!generate_key(path)) {
|
||||||
D("Failed to generate new key\n");
|
D("Failed to generate new key\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return read_key(path.c_str(), list);
|
return read_key(path, list);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void get_vendor_keys(struct listnode* key_list) {
|
static void get_vendor_keys(struct listnode* key_list) {
|
||||||
|
|
@ -408,26 +411,27 @@ void *adb_auth_nextkey(void *current)
|
||||||
|
|
||||||
int adb_auth_get_userkey(unsigned char *data, size_t len)
|
int adb_auth_get_userkey(unsigned char *data, size_t len)
|
||||||
{
|
{
|
||||||
std::string path;
|
char path[PATH_MAX];
|
||||||
if (!get_user_keyfilepath(&path)) {
|
int ret = get_user_keyfilepath(path, sizeof(path) - 4);
|
||||||
|
if (ret < 0 || ret >= (signed)(sizeof(path) - 4)) {
|
||||||
D("Error getting user key filename");
|
D("Error getting user key filename");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
path += ".pub";
|
strcat(path, ".pub");
|
||||||
|
|
||||||
// TODO(danalbert): ReadFileToString
|
// TODO(danalbert): ReadFileToString
|
||||||
// Note that on Windows, load_file() does not do CR/LF translation, but
|
// Note that on Windows, load_file() does not do CR/LF translation, but
|
||||||
// ReadFileToString() uses the C Runtime which uses CR/LF translation by
|
// ReadFileToString() uses the C Runtime which uses CR/LF translation by
|
||||||
// default (by is overridable with _setmode()).
|
// default (by is overridable with _setmode()).
|
||||||
unsigned size;
|
unsigned size;
|
||||||
void* file_data = load_file(path.c_str(), &size);
|
char* file_data = reinterpret_cast<char*>(load_file(path, &size));
|
||||||
if (file_data == nullptr) {
|
if (file_data == nullptr) {
|
||||||
D("Can't load '%s'\n", path.c_str());
|
D("Can't load '%s'\n", path);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (len < (size_t)(size + 1)) {
|
if (len < (size_t)(size + 1)) {
|
||||||
D("%s: Content too large ret=%d\n", path.c_str(), size);
|
D("%s: Content too large ret=%d\n", path, size);
|
||||||
free(file_data);
|
free(file_data);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,8 +21,6 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "base/macros.h"
|
|
||||||
|
|
||||||
// Sends the protocol "OKAY" message.
|
// Sends the protocol "OKAY" message.
|
||||||
bool SendOkay(int fd);
|
bool SendOkay(int fd);
|
||||||
|
|
||||||
|
|
@ -56,6 +54,6 @@ bool WriteFdExactly(int fd, const char* s);
|
||||||
bool WriteFdExactly(int fd, const std::string& s);
|
bool WriteFdExactly(int fd, const std::string& s);
|
||||||
|
|
||||||
// Same as above, but formats the string to send.
|
// Same as above, but formats the string to send.
|
||||||
bool WriteFdFmt(int fd, const char* fmt, ...) ATTRIBUTE_FORMAT(2, 3);
|
bool WriteFdFmt(int fd, const char* fmt, ...) __attribute__((__format__(__printf__, 2, 3)));
|
||||||
|
|
||||||
#endif /* ADB_IO_H */
|
#endif /* ADB_IO_H */
|
||||||
|
|
|
||||||
|
|
@ -42,11 +42,6 @@ bool directory_exists(const std::string& path) {
|
||||||
return lstat(path.c_str(), &sb) != -1 && S_ISDIR(sb.st_mode);
|
return lstat(path.c_str(), &sb) != -1 && S_ISDIR(sb.st_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool file_exists(const std::string& path) {
|
|
||||||
struct stat sb;
|
|
||||||
return lstat(path.c_str(), &sb) != -1 && S_ISREG(sb.st_mode);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string escape_arg(const std::string& s) {
|
std::string escape_arg(const std::string& s) {
|
||||||
std::string result = s;
|
std::string result = s;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,6 @@
|
||||||
|
|
||||||
bool getcwd(std::string* cwd);
|
bool getcwd(std::string* cwd);
|
||||||
bool directory_exists(const std::string& path);
|
bool directory_exists(const std::string& path);
|
||||||
bool file_exists(const std::string& path);
|
|
||||||
|
|
||||||
std::string escape_arg(const std::string& s);
|
std::string escape_arg(const std::string& s);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1447,8 +1447,7 @@ static int uninstall_app(TransportType transport, const char* serial, int argc,
|
||||||
return pm_command(transport, serial, argc, argv);
|
return pm_command(transport, serial, argc, argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int delete_file(TransportType transport, const char* serial,
|
static int delete_file(TransportType transport, const char* serial, char* filename) {
|
||||||
const char* filename) {
|
|
||||||
std::string cmd = "shell:rm -f " + escape_arg(filename);
|
std::string cmd = "shell:rm -f " + escape_arg(filename);
|
||||||
return send_shell_command(transport, serial, cmd);
|
return send_shell_command(transport, serial, cmd);
|
||||||
}
|
}
|
||||||
|
|
@ -1465,8 +1464,8 @@ static const char* get_basename(const char* filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int install_app(TransportType transport, const char* serial, int argc, const char** argv) {
|
static int install_app(TransportType transport, const char* serial, int argc, const char** argv) {
|
||||||
static const char *const DATA_DEST = "/data/local/tmp";
|
static const char *const DATA_DEST = "/data/local/tmp/%s";
|
||||||
static const char *const SD_DEST = "/sdcard/tmp";
|
static const char *const SD_DEST = "/sdcard/tmp/%s";
|
||||||
const char* where = DATA_DEST;
|
const char* where = DATA_DEST;
|
||||||
int i;
|
int i;
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
|
|
@ -1500,20 +1499,19 @@ static int install_app(TransportType transport, const char* serial, int argc, co
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* apk_file = argv[last_apk];
|
const char* apk_file = argv[last_apk];
|
||||||
const std::string apk_dest =
|
char apk_dest[PATH_MAX];
|
||||||
android::base::StringPrintf("%s/%s", where, get_basename(apk_file));
|
snprintf(apk_dest, sizeof apk_dest, where, get_basename(apk_file));
|
||||||
int err = do_sync_push(apk_file, apk_dest.c_str(), /* show_progress = */ 0);
|
int err = do_sync_push(apk_file, apk_dest, 0 /* no show progress */);
|
||||||
if (err) {
|
if (err) {
|
||||||
goto cleanup_apk;
|
goto cleanup_apk;
|
||||||
} else {
|
} else {
|
||||||
// Destination name, not source location.
|
argv[last_apk] = apk_dest; /* destination name, not source location */
|
||||||
argv[last_apk] = apk_dest.c_str();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err = pm_command(transport, serial, argc, argv);
|
err = pm_command(transport, serial, argc, argv);
|
||||||
|
|
||||||
cleanup_apk:
|
cleanup_apk:
|
||||||
delete_file(transport, serial, apk_dest.c_str());
|
delete_file(transport, serial, apk_dest);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,8 +30,6 @@
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "base/macros.h"
|
|
||||||
|
|
||||||
#include "adb_io.h"
|
#include "adb_io.h"
|
||||||
#include "adb_trace.h"
|
#include "adb_trace.h"
|
||||||
|
|
||||||
|
|
@ -46,7 +44,6 @@
|
||||||
// of the shell's pseudo-tty master. I.e. force close it.
|
// of the shell's pseudo-tty master. I.e. force close it.
|
||||||
int SHELL_EXIT_NOTIFY_FD = -1;
|
int SHELL_EXIT_NOTIFY_FD = -1;
|
||||||
|
|
||||||
static void fatal(const char *fn, const char *fmt, ...) ATTRIBUTE_FORMAT(2, 3);
|
|
||||||
static void fatal(const char *fn, const char *fmt, ...)
|
static void fatal(const char *fn, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
|
||||||
|
|
@ -21,10 +21,8 @@
|
||||||
#ifndef __QEMU_TRACING_H
|
#ifndef __QEMU_TRACING_H
|
||||||
#define __QEMU_TRACING_H
|
#define __QEMU_TRACING_H
|
||||||
|
|
||||||
#include "base/macros.h"
|
|
||||||
|
|
||||||
/* Initializes connection with the adb-debug qemud service in the emulator. */
|
/* Initializes connection with the adb-debug qemud service in the emulator. */
|
||||||
int adb_qemu_trace_init(void);
|
int adb_qemu_trace_init(void);
|
||||||
void adb_qemu_trace(const char* fmt, ...) ATTRIBUTE_FORMAT(1, 2);
|
void adb_qemu_trace(const char* fmt, ...);
|
||||||
|
|
||||||
#endif /* __QEMU_TRACING_H */
|
#endif /* __QEMU_TRACING_H */
|
||||||
|
|
|
||||||
|
|
@ -185,17 +185,4 @@ void UNUSED(const T&...) {
|
||||||
} while (0)
|
} while (0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// These printf-like functions are implemented in terms of vsnprintf, so they
|
|
||||||
// use the same attribute for compile-time format string checking. On Windows,
|
|
||||||
// if the mingw version of vsnprintf is used, so use `gnu_printf' which allows z
|
|
||||||
// in %zd and PRIu64 (and related) to be recognized by the compile-time
|
|
||||||
// checking.
|
|
||||||
#if defined(__USE_MINGW_ANSI_STDIO) && __USE_MINGW_ANSI_STDIO
|
|
||||||
#define ATTRIBUTE_FORMAT(fmt, args) \
|
|
||||||
__attribute__((format(gnu_printf, fmt, args)))
|
|
||||||
#else
|
|
||||||
#define ATTRIBUTE_FORMAT(fmt, args) \
|
|
||||||
__attribute__((format(__printf__, fmt, args)))
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // UTILS_MACROS_H
|
#endif // UTILS_MACROS_H
|
||||||
|
|
|
||||||
|
|
@ -20,21 +20,35 @@
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "base/macros.h"
|
|
||||||
|
|
||||||
namespace android {
|
namespace android {
|
||||||
namespace base {
|
namespace base {
|
||||||
|
|
||||||
|
// These printf-like functions are implemented in terms of vsnprintf, so they
|
||||||
|
// use the same attribute for compile-time format string checking. On Windows,
|
||||||
|
// if the mingw version of vsnprintf is used, use `gnu_printf' which allows z
|
||||||
|
// in %zd and PRIu64 (and related) to be recognized by the compile-time
|
||||||
|
// checking.
|
||||||
|
#define FORMAT_ARCHETYPE __printf__
|
||||||
|
#ifdef __USE_MINGW_ANSI_STDIO
|
||||||
|
#if __USE_MINGW_ANSI_STDIO
|
||||||
|
#undef FORMAT_ARCHETYPE
|
||||||
|
#define FORMAT_ARCHETYPE gnu_printf
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
// Returns a string corresponding to printf-like formatting of the arguments.
|
// Returns a string corresponding to printf-like formatting of the arguments.
|
||||||
std::string StringPrintf(const char* fmt, ...) ATTRIBUTE_FORMAT(1, 2);
|
std::string StringPrintf(const char* fmt, ...)
|
||||||
|
__attribute__((__format__(FORMAT_ARCHETYPE, 1, 2)));
|
||||||
|
|
||||||
// Appends a printf-like formatting of the arguments to 'dst'.
|
// Appends a printf-like formatting of the arguments to 'dst'.
|
||||||
void StringAppendF(std::string* dst, const char* fmt, ...)
|
void StringAppendF(std::string* dst, const char* fmt, ...)
|
||||||
ATTRIBUTE_FORMAT(2, 3);
|
__attribute__((__format__(FORMAT_ARCHETYPE, 2, 3)));
|
||||||
|
|
||||||
// Appends a printf-like formatting of the arguments to 'dst'.
|
// Appends a printf-like formatting of the arguments to 'dst'.
|
||||||
void StringAppendV(std::string* dst, const char* format, va_list ap)
|
void StringAppendV(std::string* dst, const char* format, va_list ap)
|
||||||
ATTRIBUTE_FORMAT(2, 0);
|
__attribute__((__format__(FORMAT_ARCHETYPE, 2, 0)));
|
||||||
|
|
||||||
|
#undef FORMAT_ARCHETYPE
|
||||||
|
|
||||||
} // namespace base
|
} // namespace base
|
||||||
} // namespace android
|
} // namespace android
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue