[vfs] stricter input checks in macOS filesystem event helper (IJ-CR-95917)

GitOrigin-RevId: 7f930ae26142688684042ae3979bc8a76cd79f61
This commit is contained in:
Roman Shevchenko
2022-10-05 10:24:32 +02:00
committed by intellij-monorepo-bot
parent e05e91581d
commit 1938f0f5b8

View File

@@ -114,9 +114,9 @@ static void PrintMountedFileSystems(CFArrayRef roots) {
#define INPUT_BUF_LEN 2048 #define INPUT_BUF_LEN 2048
static char input_buf[INPUT_BUF_LEN]; static char input_buf[INPUT_BUF_LEN];
static char* read_line(FILE* stream) { static char *read_stdin() {
char* result = fgets(input_buf, INPUT_BUF_LEN, stream); char* result = fgets(input_buf, INPUT_BUF_LEN, stdin);
if (result == NULL || feof(stream)) { if (result == NULL || feof(stdin)) {
return NULL; return NULL;
} }
size_t pos = strlen(input_buf) - 1; size_t pos = strlen(input_buf) - 1;
@@ -126,13 +126,14 @@ static char* read_line(FILE* stream) {
return input_buf; return input_buf;
} }
static void ParseRoots() { static bool ParseRoots() {
CFMutableArrayRef roots = CFArrayCreateMutable(NULL, 0, NULL); CFMutableArrayRef roots = CFArrayCreateMutable(NULL, 0, NULL);
bool has_private_root = false; bool has_private_root = false;
while (TRUE) { while (TRUE) {
char *command = read_line(stdin); char *command = read_stdin();
if (strcmp(command, "#") == 0 || feof(stdin)) break; if (command == NULL) return false;
if (strcmp(command, "#") == 0) break;
char *path = command[0] == '|' ? command + 1 : command; char *path = command[0] == '|' ? command + 1 : command;
CFArrayAppendValue(roots, strdup(path)); CFArrayAppendValue(roots, strdup(path));
if (strcmp(path, "/") == 0 || strncasecmp(path, PRIVATE_DIR, PRIVATE_LEN) == 0) { if (strcmp(path, "/") == 0 || strncasecmp(path, PRIVATE_DIR, PRIVATE_LEN) == 0) {
@@ -151,6 +152,7 @@ static void ParseRoots() {
free(value); free(value);
} }
CFRelease(roots); CFRelease(roots);
return true;
} }
int main(void) { int main(void) {
@@ -178,9 +180,11 @@ int main(void) {
} }
while (TRUE) { while (TRUE) {
char *command = read_line(stdin); char *command = read_stdin();
if (strcmp(command, "EXIT") == 0 || feof(stdin)) break; if (command == NULL || strcmp(command, "EXIT") == 0) break;
if (strcmp(command, "ROOTS") == 0) ParseRoots(); if (strcmp(command, "ROOTS") == 0) {
if (!ParseRoots()) break;
}
} }
return 0; return 0;