• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Aucun tag

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

external/koush/Superuser


Commit MetaInfo

Révision72d541291ef543eec7ab08fd9f3048a4efe2df2e (tree)
l'heure2013-08-12 10:05:11
AuteurKoushik Dutta <koushd@gmai...>
CommiterKoushik Dutta

Message de Log

sanitize inputs. verify mallocs.

Change-Id: If5d7a51ca56c4dba6948d2f405f41721a15a16b6

Change Summary

Modification

--- a/Superuser/jni/su/daemon.c
+++ b/Superuser/jni/su/daemon.c
@@ -45,7 +45,7 @@ int daemon_from_pid = 0;
4545 static int read_int(int fd) {
4646 int val;
4747 int len = read(fd, &val, sizeof(int));
48- if (len < sizeof(int)) {
48+ if (len != sizeof(int)) {
4949 LOGE("unable to read int");
5050 exit(-1);
5151 }
@@ -62,11 +62,15 @@ static void write_int(int fd, int val) {
6262
6363 static char* read_string(int fd) {
6464 int len = read_int(fd);
65- if (len > PATH_MAX) {
66- LOGE("string too long");
65+ if (len > PATH_MAX || len < 0) {
66+ LOGE("invalid string length %d", len);
6767 exit(-1);
6868 }
6969 char* val = malloc(sizeof(char) * (len + 1));
70+ if (val == NULL) {
71+ LOGE("unable to malloc string");
72+ exit(-1);
73+ }
7074 val[len] = '\0';
7175 int amount = read(fd, val, len);
7276 if (amount != len) {
@@ -131,6 +135,10 @@ static void* pump_thread(void* data) {
131135 static void pump_async(int input, int output) {
132136 pthread_t writer;
133137 int* files = (int*)malloc(sizeof(int) * 2);
138+ if (files == NULL) {
139+ LOGE("unable to pump_async");
140+ exit(-1);
141+ }
134142 files[0] = input;
135143 files[1] = output;
136144 pthread_create(&writer, NULL, pump_thread, files);
@@ -147,6 +155,10 @@ static int daemon_accept(int fd) {
147155 daemon_from_pid = read_int(fd);
148156 LOGD("remote req pid: %d", daemon_from_pid);
149157 int argc = read_int(fd);
158+ if (argc < 0 || argc > 512) {
159+ LOGE("unable to allocate args: %d", argc);
160+ exit(-1);
161+ }
150162 LOGD("remote args: %d", argc);
151163 char** argv = (char**)malloc(sizeof(char*) * (argc + 1));
152164 argv[argc] = NULL;