From 553fb024d49aa75df40b4f09208f93ce381aa00f Mon Sep 17 00:00:00 2001 From: sfan5 Date: Mon, 13 May 2024 21:55:51 +0200 Subject: [PATCH] stream: check file descriptor passed to fd:// or fdclose:// --- stream/stream_file.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/stream/stream_file.c b/stream/stream_file.c index 1744fc13a4..d5c2aaa673 100644 --- a/stream/stream_file.c +++ b/stream/stream_file.c @@ -299,10 +299,16 @@ static int open_f(stream_t *stream, const struct stream_open_args *args) if (strncmp(url, "fd://", 5) == 0 || is_fdclose) { char *begin = strstr(stream->url, "://") + 3, *end = NULL; p->fd = strtol(begin, &end, 0); - if (!end || end == begin || end[0]) { - MP_ERR(stream, "Invalid FD: %s\n", stream->url); + if (!end || end == begin || end[0] || p->fd < 0) { + MP_ERR(stream, "Invalid FD number: %s\n", stream->url); return STREAM_ERROR; } +#ifdef F_SETFD + if (fcntl(p->fd, F_GETFD) == -1) { + MP_ERR(stream, "Invalid FD: %d\n", p->fd); + return STREAM_ERROR; + } +#endif if (is_fdclose) p->close = true; } else if (!strict_fs && !strcmp(filename, "-")) {