Loading adb/adb.c +13 −1 Original line number Diff line number Diff line Loading @@ -859,8 +859,20 @@ int adb_main(int is_daemon) property_get("ro.kernel.qemu", value, ""); if (strcmp(value, "1") != 0) { property_get("ro.secure", value, ""); if (strcmp(value, "1") == 0) if (strcmp(value, "1") == 0) { // don't run as root if ro.secure is set... secure = 1; // ... except we allow running as root in userdebug builds if the // service.adb.root property has been set by the "adb root" command property_get("ro.debuggable", value, ""); if (strcmp(value, "1") == 0) { property_get("service.adb.root", value, ""); if (strcmp(value, "1") == 0) { secure = 0; } } } } /* don't listen on port 5037 if we are running in secure mode */ Loading adb/commandline.c +12 −0 Original line number Diff line number Diff line Loading @@ -147,6 +147,7 @@ void help() " adb get-serialno - prints: <serial-number>\n" " adb status-window - continuously print device status for a specified device\n" " adb remount - remounts the /system partition on the device read-write\n" " adb root - restarts adb with root permissions\n" "\n" "networking:\n" " adb ppp <tty> [parameters] - Run PPP over USB.\n" Loading Loading @@ -914,6 +915,17 @@ top: return 1; } if(!strcmp(argv[0], "root")) { int fd = adb_connect("root:"); if(fd >= 0) { read_and_dump(fd); adb_close(fd); return 0; } fprintf(stderr,"error: %s\n", adb_error()); return 1; } if(!strcmp(argv[0], "bugreport")) { if (argc != 1) { return 1; Loading adb/services.c +30 −0 Original line number Diff line number Diff line Loading @@ -103,6 +103,34 @@ static void recover_service(int s, void *cookie) adb_close(fd); } void restart_root_service(int fd, void *cookie) { char buf[100]; char value[PROPERTY_VALUE_MAX]; if (getuid() == 0) { snprintf(buf, sizeof(buf), "adbd is already running as root\n"); writex(fd, buf, strlen(buf)); adb_close(fd); } else { property_get("ro.debuggable", value, ""); if (strcmp(value, "1") != 0) { snprintf(buf, sizeof(buf), "adbd cannot run as root in production builds\n"); writex(fd, buf, strlen(buf)); return; } property_set("service.adb.root", "1"); snprintf(buf, sizeof(buf), "restarting adbd as root\n"); writex(fd, buf, strlen(buf)); adb_close(fd); // quit, and init will restart us as root sleep(1); exit(1); } } #endif #if 0 Loading Loading @@ -289,6 +317,8 @@ int service_to_fd(const char *name) ret = create_service_thread(file_sync_service, NULL); } else if(!strncmp(name, "remount:", 8)) { ret = create_service_thread(remount_service, NULL); } else if(!strncmp(name, "root:", 5)) { ret = create_service_thread(restart_root_service, NULL); #endif #if 0 } else if(!strncmp(name, "echo:", 5)){ Loading init/property_service.c +1 −0 Original line number Diff line number Diff line Loading @@ -69,6 +69,7 @@ struct { { "dhcp.", AID_DHCP }, { "debug.", AID_SHELL }, { "log.", AID_SHELL }, { "service.adb.root", AID_SHELL }, { "persist.sys.", AID_SYSTEM }, { "persist.service.", AID_SYSTEM }, { NULL, 0 } Loading libcutils/array.c +21 −6 Original line number Diff line number Diff line Loading @@ -18,8 +18,10 @@ #include <assert.h> #include <stdlib.h> #include <string.h> #include <limits.h> #define INITIAL_CAPACITY (4) #define MAX_CAPACITY ((int)(UINT_MAX/sizeof(void*))) struct Array { void** contents; Loading @@ -45,13 +47,26 @@ void arrayFree(Array* array) { static int ensureCapacity(Array* array, int capacity) { int oldCapacity = array->capacity; if (capacity > oldCapacity) { int newCapacity = (oldCapacity == 0) ? INITIAL_CAPACITY : oldCapacity * 2; int newCapacity = (oldCapacity == 0) ? INITIAL_CAPACITY : oldCapacity; // Ensure we're not doing something nasty if (capacity > MAX_CAPACITY) return -1; // Keep doubling capacity until we surpass necessary capacity. while (newCapacity < capacity) { newCapacity *= 2; int newCap = newCapacity*2; // Handle integer overflows if (newCap < newCapacity || newCap > MAX_CAPACITY) { newCap = MAX_CAPACITY; } newCapacity = newCap; } // Should not happen, but better be safe than sorry if (newCapacity < 0 || newCapacity > MAX_CAPACITY) return -1; void** newContents; if (array->contents == NULL) { // Allocate new array. Loading Loading @@ -151,5 +166,5 @@ int arraySize(Array* array) { } const void** arrayUnwrap(Array* array) { return array->contents; return (const void**)array->contents; } Loading
adb/adb.c +13 −1 Original line number Diff line number Diff line Loading @@ -859,8 +859,20 @@ int adb_main(int is_daemon) property_get("ro.kernel.qemu", value, ""); if (strcmp(value, "1") != 0) { property_get("ro.secure", value, ""); if (strcmp(value, "1") == 0) if (strcmp(value, "1") == 0) { // don't run as root if ro.secure is set... secure = 1; // ... except we allow running as root in userdebug builds if the // service.adb.root property has been set by the "adb root" command property_get("ro.debuggable", value, ""); if (strcmp(value, "1") == 0) { property_get("service.adb.root", value, ""); if (strcmp(value, "1") == 0) { secure = 0; } } } } /* don't listen on port 5037 if we are running in secure mode */ Loading
adb/commandline.c +12 −0 Original line number Diff line number Diff line Loading @@ -147,6 +147,7 @@ void help() " adb get-serialno - prints: <serial-number>\n" " adb status-window - continuously print device status for a specified device\n" " adb remount - remounts the /system partition on the device read-write\n" " adb root - restarts adb with root permissions\n" "\n" "networking:\n" " adb ppp <tty> [parameters] - Run PPP over USB.\n" Loading Loading @@ -914,6 +915,17 @@ top: return 1; } if(!strcmp(argv[0], "root")) { int fd = adb_connect("root:"); if(fd >= 0) { read_and_dump(fd); adb_close(fd); return 0; } fprintf(stderr,"error: %s\n", adb_error()); return 1; } if(!strcmp(argv[0], "bugreport")) { if (argc != 1) { return 1; Loading
adb/services.c +30 −0 Original line number Diff line number Diff line Loading @@ -103,6 +103,34 @@ static void recover_service(int s, void *cookie) adb_close(fd); } void restart_root_service(int fd, void *cookie) { char buf[100]; char value[PROPERTY_VALUE_MAX]; if (getuid() == 0) { snprintf(buf, sizeof(buf), "adbd is already running as root\n"); writex(fd, buf, strlen(buf)); adb_close(fd); } else { property_get("ro.debuggable", value, ""); if (strcmp(value, "1") != 0) { snprintf(buf, sizeof(buf), "adbd cannot run as root in production builds\n"); writex(fd, buf, strlen(buf)); return; } property_set("service.adb.root", "1"); snprintf(buf, sizeof(buf), "restarting adbd as root\n"); writex(fd, buf, strlen(buf)); adb_close(fd); // quit, and init will restart us as root sleep(1); exit(1); } } #endif #if 0 Loading Loading @@ -289,6 +317,8 @@ int service_to_fd(const char *name) ret = create_service_thread(file_sync_service, NULL); } else if(!strncmp(name, "remount:", 8)) { ret = create_service_thread(remount_service, NULL); } else if(!strncmp(name, "root:", 5)) { ret = create_service_thread(restart_root_service, NULL); #endif #if 0 } else if(!strncmp(name, "echo:", 5)){ Loading
init/property_service.c +1 −0 Original line number Diff line number Diff line Loading @@ -69,6 +69,7 @@ struct { { "dhcp.", AID_DHCP }, { "debug.", AID_SHELL }, { "log.", AID_SHELL }, { "service.adb.root", AID_SHELL }, { "persist.sys.", AID_SYSTEM }, { "persist.service.", AID_SYSTEM }, { NULL, 0 } Loading
libcutils/array.c +21 −6 Original line number Diff line number Diff line Loading @@ -18,8 +18,10 @@ #include <assert.h> #include <stdlib.h> #include <string.h> #include <limits.h> #define INITIAL_CAPACITY (4) #define MAX_CAPACITY ((int)(UINT_MAX/sizeof(void*))) struct Array { void** contents; Loading @@ -45,13 +47,26 @@ void arrayFree(Array* array) { static int ensureCapacity(Array* array, int capacity) { int oldCapacity = array->capacity; if (capacity > oldCapacity) { int newCapacity = (oldCapacity == 0) ? INITIAL_CAPACITY : oldCapacity * 2; int newCapacity = (oldCapacity == 0) ? INITIAL_CAPACITY : oldCapacity; // Ensure we're not doing something nasty if (capacity > MAX_CAPACITY) return -1; // Keep doubling capacity until we surpass necessary capacity. while (newCapacity < capacity) { newCapacity *= 2; int newCap = newCapacity*2; // Handle integer overflows if (newCap < newCapacity || newCap > MAX_CAPACITY) { newCap = MAX_CAPACITY; } newCapacity = newCap; } // Should not happen, but better be safe than sorry if (newCapacity < 0 || newCapacity > MAX_CAPACITY) return -1; void** newContents; if (array->contents == NULL) { // Allocate new array. Loading Loading @@ -151,5 +166,5 @@ int arraySize(Array* array) { } const void** arrayUnwrap(Array* array) { return array->contents; return (const void**)array->contents; }