stream: check file descriptor passed to fd:// or fdclose://

This commit is contained in:
sfan5 committed 2024-05-15 22:45:18 +02:00
1 parent 54c755b08d
commit 553fb024d4
1 file changed
+8 -2
+8 -2
View File
@@ -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, "-")) {