Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix undefined behavior spots #9

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions adb/adb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,14 @@ std::string get_connection_string() {
"ro.product.device",
};

#if ADB_NON_ANDROID
{
char value[PROPERTY_VALUE_MAX] = "ADB non-Android";
const auto& prop_name = cnxn_props[0];
#else
for (const auto& prop_name : cnxn_props) {
char value[PROPERTY_VALUE_MAX];
#endif
property_get(prop_name, value, "");
connection_properties.push_back(
android::base::StringPrintf("%s=%s", prop_name, value));
Expand Down
4 changes: 4 additions & 0 deletions adb/adb_auth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@
#include "adb.h"
#include "transport.h"

#if ADB_NON_ANDROID
bool auth_required = false;
#else
bool auth_required = true;
#endif

void send_auth_request(atransport *t)
{
Expand Down
22 changes: 14 additions & 8 deletions adb/daemon/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@

#include <android-base/logging.h>
#include <android-base/stringprintf.h>
#ifndef ADB_NON_ANDROID
#include <libminijail.h>
#endif

#include "cutils/properties.h"
#ifndef ADB_NON_ANDROID

#if !ADB_NON_ANDROID
#include <libminijail.h>

#include "debuggerd/client.h"
#include "private/android_filesystem_config.h"
#include "selinux/android.h"
Expand All @@ -49,7 +49,7 @@

static const char* root_seclabel = nullptr;

#ifndef ADB_NON_ANDROID
#if !ADB_NON_ANDROID
static void drop_capabilities_bounding_set_if_needed(struct minijail *j) {
#if defined(ALLOW_ADBD_ROOT)
char value[PROPERTY_VALUE_MAX];
Expand Down Expand Up @@ -167,9 +167,11 @@ int adbd_main(int server_port) {
// descriptor will always be open.
adbd_cloexec_auth_socket();

#if !ADB_NON_ANDROID
if (ALLOW_ADBD_NO_AUTH && property_get_bool("ro.adb.secure", 0) == 0) {
auth_required = false;
}
#endif

adbd_auth_init();

Expand All @@ -183,7 +185,7 @@ int adbd_main(int server_port) {
" unchanged.\n");
}

#ifndef ADB_NON_ANDROID
#if !ADB_NON_ANDROID
drop_privileges(server_port);
#endif

Expand All @@ -197,7 +199,11 @@ int adbd_main(int server_port) {
// If one of these properties is set, also listen on that port.
// If one of the properties isn't set and we couldn't listen on usb, listen
// on the default port.
#if ADB_NON_ANDROID
char prop_port[PROPERTY_VALUE_MAX] = "5555";
#else
char prop_port[PROPERTY_VALUE_MAX];
#endif
property_get("service.adb.tcp.port", prop_port, "");
if (prop_port[0] == '\0') {
property_get("persist.adb.tcp.port", prop_port, "");
Expand All @@ -213,7 +219,7 @@ int adbd_main(int server_port) {
local_init(DEFAULT_ADB_LOCAL_TRANSPORT_PORT);
}

#ifndef ADB_NON_ANDROID
#if !ADB_NON_ANDROID
D("adbd_main(): pre init_jdwp()");
init_jdwp();
D("adbd_main(): post init_jdwp()");
Expand Down Expand Up @@ -260,7 +266,7 @@ int main(int argc, char** argv) {

close_stdin();

#ifndef ADB_NON_ANDROID
#if !ADB_NON_ANDROID
debuggerd_init(nullptr);
#endif
adb_trace_init(argv);
Expand Down
4 changes: 1 addition & 3 deletions adb/file_sync_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,9 @@
#include <android-base/stringprintf.h>
#include <android-base/strings.h>
#include <log/log.h>
#ifndef ADB_NON_ANDROID
#if !ADB_NON_ANDROID
#include <selinux/android.h>
#endif

#if !ADB_NON_ANDROID
static bool should_use_fs_config(const std::string& path) {
// TODO: use fs_config to configure permissions on /data.
return android::base::StartsWith(path, "/system/") ||
Expand Down
6 changes: 5 additions & 1 deletion adb/services.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ void restart_root_service(int fd, void *cookie) {
WriteFdExactly(fd, "adbd is already running as root\n");
adb_close(fd);
} else {
#if ADB_NON_ANDROID
char value[PROPERTY_VALUE_MAX] = "1";
#else
char value[PROPERTY_VALUE_MAX];
#endif
property_get("ro.debuggable", value, "");
if (strcmp(value, "1") != 0) {
WriteFdExactly(fd, "adbd cannot run as root in production builds\n");
Expand Down Expand Up @@ -319,7 +323,7 @@ int service_to_fd(const char* name, const atransport* transport) {
ret = unix_open(name + 4, O_RDWR | O_CLOEXEC);
} else if(!strncmp(name, "framebuffer:", 12)) {
ret = create_service_thread(framebuffer_service, 0);
#ifndef ADB_NON_ANDROID
#if !ADB_NON_ANDROID
} else if (!strncmp(name, "jdwp:", 5)) {
ret = create_jdwp_connection_fd(atoi(name+5));
#endif
Expand Down
4 changes: 4 additions & 0 deletions adb/sockets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,11 @@ asocket* create_local_service_socket(const char* name, const atransport* transpo
D("LS(%d): bound to '%s' via %d", s->id, name, fd);

#if !ADB_HOST
#if ADB_NON_ANDROID
char debug[PROPERTY_VALUE_MAX] = "1";
#else
char debug[PROPERTY_VALUE_MAX];
#endif
if (!strncmp(name, "root:", 5)) {
property_get("ro.debuggable", debug, "");
}
Expand Down
4 changes: 4 additions & 0 deletions adb/transport_local.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,11 @@ void local_init(int port)
#else
/* For the adbd daemon in the system image we need to distinguish
* between the device, and the emulator. */
#if ADB_NON_ANDROID
char is_qemu[PROPERTY_VALUE_MAX] = "0";
#else
char is_qemu[PROPERTY_VALUE_MAX];
#endif
property_get("ro.kernel.qemu", is_qemu, "");
if (!strcmp(is_qemu, "1")) {
/* Running inside the emulator: use QEMUD pipe as the transport. */
Expand Down
2 changes: 1 addition & 1 deletion base/utf8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

#ifndef ADB_NON_ANDROID
#ifdef _WIN32
#include <windows.h>
#endif

Expand Down