From 40f1a89e40096ee2ac5c2f214261afb929a12b0f Mon Sep 17 00:00:00 2001 From: nanahi <130121847+na-na-hi@users.noreply.github.com> Date: Mon, 29 Jul 2024 04:20:59 -0400 Subject: [PATCH] input/ipc: use bstr for fd parsing Also rejects the case of "fd://" without any number which was silently accepted as 0. --- input/ipc-unix.c | 10 +++++----- input/ipc-win.c | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/input/ipc-unix.c b/input/ipc-unix.c index a416b54e1e..11468e48bd 100644 --- a/input/ipc-unix.c +++ b/input/ipc-unix.c @@ -395,11 +395,11 @@ struct mp_ipc_ctx *mp_init_ipc(struct mp_client_api *client_api, if (opts->ipc_client && opts->ipc_client[0]) { int fd = -1; - if (strncmp(opts->ipc_client, "fd://", 5) == 0) { - char *end; - unsigned long l = strtoul(opts->ipc_client + 5, &end, 0); - if (!end[0] && l <= INT_MAX) - fd = l; + bstr str = bstr0(opts->ipc_client); + if (bstr_eatstart0(&str, "fd://") && str.len) { + long long ll = bstrtoll(str, &str, 0); + if (!str.len && ll >= 0 && ll <= INT_MAX) + fd = ll; } if (fd < 0) { MP_ERR(arg, "Invalid IPC client argument: '%s'\n", opts->ipc_client); diff --git a/input/ipc-win.c b/input/ipc-win.c index c215a25953..b7e54669ab 100644 --- a/input/ipc-win.c +++ b/input/ipc-win.c @@ -466,11 +466,11 @@ struct mp_ipc_ctx *mp_init_ipc(struct mp_client_api *client_api, if (opts->ipc_client && opts->ipc_client[0]) { int fd = -1; - if (strncmp(opts->ipc_client, "fd://", 5) == 0) { - char *end; - unsigned long l = strtoul(opts->ipc_client + 5, &end, 0); - if (!end[0] && l <= INT_MAX) - fd = l; + bstr str = bstr0(opts->ipc_client); + if (bstr_eatstart0(&str, "fd://") && str.len) { + long long ll = bstrtoll(str, &str, 0); + if (!str.len && ll >= 0 && ll <= INT_MAX) + fd = ll; } if (fd < 0) { MP_ERR(arg, "Invalid IPC client argument: '%s'\n", opts->ipc_client);