Skip to content

Commit

Permalink
input/ipc: use bstr for fd parsing
Browse files Browse the repository at this point in the history
Also rejects the case of "fd://" without any number which was
silently accepted as 0.
  • Loading branch information
na-na-hi authored and kasper93 committed Jul 29, 2024
1 parent bb0932a commit 40f1a89
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions input/ipc-unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions input/ipc-win.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 40f1a89

Please sign in to comment.