From e2e76c5d4858530db691a4d8c2bb7a97eaebdfb3 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Fri, 18 Feb 2022 21:33:20 +0100 Subject: [PATCH] Increase `adb devices -l` max output size For simplicity, the parsing of `adb devices -l` output is performed in a single pass on the whole output. This output was limited to 4096 bytes. Since there are about 100 chars per device line, this limited the number of connected devices to ~40. Increase to 65536 bytes to avoid a limitation in practice. PR #3035 --- app/src/adb/adb.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/app/src/adb/adb.c b/app/src/adb/adb.c index c14ded92..06090b46 100644 --- a/app/src/adb/adb.c +++ b/app/src/adb/adb.c @@ -398,31 +398,39 @@ sc_adb_list_devices(struct sc_intr *intr, unsigned flags, struct sc_vec_adb_devices *out_vec) { const char *const argv[] = SC_ADB_COMMAND("devices", "-l"); +#define BUFSIZE 65536 + char *buf = malloc(BUFSIZE); + if (!buf) { + return false; + } + sc_pipe pout; sc_pid pid = sc_adb_execute_p(argv, flags, &pout); if (pid == SC_PROCESS_NONE) { LOGE("Could not execute \"adb devices -l\""); + free(buf); return false; } - char buf[4096]; - ssize_t r = sc_pipe_read_all_intr(intr, pid, pout, buf, sizeof(buf) - 1); + ssize_t r = sc_pipe_read_all_intr(intr, pid, pout, buf, BUFSIZE - 1); sc_pipe_close(pout); bool ok = process_check_success_intr(intr, pid, "adb devices -l", flags); if (!ok) { + free(buf); return false; } if (r == -1) { + free(buf); return false; } - assert((size_t) r < sizeof(buf)); - if (r == sizeof(buf) - 1) { + assert((size_t) r < BUFSIZE); + if (r == BUFSIZE - 1) { // The implementation assumes that the output of "adb devices -l" fits // in the buffer in a single pass - LOGW("Result of \"adb devices -l\" does not fit in 4Kb. " + LOGW("Result of \"adb devices -l\" does not fit in 64Kb. " "Please report an issue."); return false; } @@ -431,7 +439,9 @@ sc_adb_list_devices(struct sc_intr *intr, unsigned flags, buf[r] = '\0'; // List all devices to the output list directly - return sc_adb_parse_devices(buf, out_vec); + ok = sc_adb_parse_devices(buf, out_vec); + free(buf); + return ok; } static bool