this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mldr: Unexpand vchroot path for `executable_path`

+21 -19
+1
src/startup/mldr/loader.h
··· 18 18 unsigned long base; 19 19 uint32_t bprefs[4]; 20 20 char* root_path; 21 + size_t root_path_length; 21 22 unsigned long stack_top; 22 23 char* socket_path; 23 24 int kernfd;
+16 -12
src/startup/mldr/mldr.c
··· 428 428 strncpy(root_path, str, sizeof(root_path) - 1); 429 429 root_path[sizeof(root_path) - 1] = '\0'; 430 430 lr->root_path = root_path; 431 + lr->root_path_length = strlen(lr->root_path); 431 432 } 432 433 }; 433 434 ··· 489 490 exit(1); 490 491 } 491 492 492 - static char vchroot_buffer[4096]; 493 - uint64_t vchroot_path_length = 0; 493 + if (!lr->root_path) { 494 + static char vchroot_buffer[4096]; 495 + uint64_t vchroot_path_length = 0; 494 496 495 - int code = dserver_rpc_vchroot_path(vchroot_buffer, sizeof(vchroot_buffer), &vchroot_path_length); 496 - if (code < 0) { 497 - fprintf(stderr, "Failed to retrieve vchroot path from darlingserver: %d\n", code); 498 - exit(1); 499 - } 497 + int code = dserver_rpc_vchroot_path(vchroot_buffer, sizeof(vchroot_buffer), &vchroot_path_length); 498 + if (code < 0) { 499 + fprintf(stderr, "Failed to retrieve vchroot path from darlingserver: %d\n", code); 500 + exit(1); 501 + } 500 502 501 - if (vchroot_path_length > 0) { 502 - lr->root_path = vchroot_buffer; 503 - } else if (vchroot_path_length >= sizeof(vchroot_buffer)) { 504 - fprintf(stderr, "Vchroot path is too large for buffer\n"); 505 - exit(1); 503 + if (vchroot_path_length >= sizeof(vchroot_buffer)) { 504 + fprintf(stderr, "Vchroot path is too large for buffer\n"); 505 + exit(1); 506 + } else if (vchroot_path_length > 0) { 507 + lr->root_path = vchroot_buffer; 508 + lr->root_path_length = vchroot_path_length; 509 + } 506 510 } 507 511 }; 508 512
+4 -7
src/startup/mldr/stack.c
··· 71 71 char __user* elfcalls_user; 72 72 char elfcalls[27]; 73 73 char __user* applep_contents[4]; 74 - char* vchroot_path = NULL; 75 74 76 75 #define user_long_count(_val) (((_val) + (sizeof(user_long_t) - 1)) / sizeof(user_long_t)) 77 76 ··· 88 87 89 88 executable_path = executable_buf; 90 89 91 - // TODO: ask darlingserver for our vchroot path 92 - 93 - if (vchroot_path != NULL) 90 + if (lr->root_path) 94 91 { 95 - const size_t vchroot_len = strlen(vchroot_path); 96 92 exepath_len = strlen(executable_path); 97 93 98 - if (strncmp(executable_path, vchroot_path, vchroot_len) == 0) 94 + if (strncmp(executable_path, lr->root_path, lr->root_path_length) == 0) 99 95 { 100 - memmove(executable_buf, executable_path + vchroot_len, exepath_len - vchroot_len + 1); 96 + memmove(executable_buf, executable_path + lr->root_path_length, exepath_len - lr->root_path_length + 1); 101 97 } 102 98 else 103 99 { 100 + // FIXME: potential buffer overflow 104 101 memcpy(executable_buf, SYSTEM_ROOT, sizeof(SYSTEM_ROOT) - 1); 105 102 memmove(executable_buf + sizeof(SYSTEM_ROOT) - 1, executable_path, exepath_len + 1); 106 103 }