diff --git a/app/src/adb/adb.c b/app/src/adb/adb.c index 2fd4b35d..11c1b298 100644 --- a/app/src/adb/adb.c +++ b/app/src/adb/adb.c @@ -417,7 +417,7 @@ sc_adb_get_serialno(struct sc_intr *intr, unsigned flags) { } char buf[128]; - ssize_t r = sc_pipe_read_all_intr(intr, pid, pout, buf, sizeof(buf)); + ssize_t r = sc_pipe_read_all_intr(intr, pid, pout, buf, sizeof(buf) - 1); sc_pipe_close(pout); bool ok = process_check_success_intr(intr, pid, "adb get-serialno", flags); @@ -429,7 +429,10 @@ sc_adb_get_serialno(struct sc_intr *intr, unsigned flags) { return NULL; } - sc_str_truncate(buf, r, " \r\n"); + assert((size_t) r < sizeof(buf)); + buf[r] = '\0'; + size_t len = strcspn(buf, " \r\n"); + buf[len] = '\0'; return strdup(buf); }