summaryrefslogtreecommitdiffstats
path: root/stream/stream.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2020-05-10 16:44:35 +0200
committerwm4 <wm4@nowhere>2020-05-10 16:44:35 +0200
commitad9f3bfe961b3f3bf3e047316419a60de8be49e7 (patch)
treefcfea7879990f74da7881a0c737f603c1bb795f5 /stream/stream.c
parenta600d152d21ef398eb72b008ee3fe266696eb638 (diff)
downloadmpv-ad9f3bfe961b3f3bf3e047316419a60de8be49e7.tar.bz2
mpv-ad9f3bfe961b3f3bf3e047316419a60de8be49e7.tar.xz
stream: make stream_read_file() more robust
Change it to strictly accept local paths only. No more http://, no more $HOME expansion with "~/" or mpv config path expansion with "~~/". This should behave as if passing a path directly to open(). Reduce annoying log noise to further facilitate it using as open() replacement.
Diffstat (limited to 'stream/stream.c')
-rw-r--r--stream/stream.c30
1 files changed, 19 insertions, 11 deletions
diff --git a/stream/stream.c b/stream/stream.c
index 0d72aa082f..8361cd8748 100644
--- a/stream/stream.c
+++ b/stream/stream.c
@@ -319,14 +319,20 @@ static int stream_create_instance(const stream_info_t *sinfo,
*ret = NULL;
const char *path = url;
- for (int n = 0; sinfo->protocols && sinfo->protocols[n]; n++) {
- path = match_proto(url, sinfo->protocols[n]);
- if (path)
- break;
- }
- if (!path)
- return STREAM_NO_MATCH;
+ if (flags & STREAM_LOCAL_FS_ONLY) {
+ if (!sinfo->local_fs)
+ return STREAM_NO_MATCH;
+ } else {
+ for (int n = 0; sinfo->protocols && sinfo->protocols[n]; n++) {
+ path = match_proto(url, sinfo->protocols[n]);
+ if (path)
+ break;
+ }
+
+ if (!path)
+ return STREAM_NO_MATCH;
+ }
stream_t *s = talloc_zero(NULL, stream_t);
s->global = args->global;
@@ -343,6 +349,9 @@ static int stream_create_instance(const stream_info_t *sinfo,
s->mode = flags & (STREAM_READ | STREAM_WRITE);
s->requested_buffer_size = opts->buffer_size;
+ if (flags & STREAM_LESS_NOISE)
+ mp_msg_set_max_level(s->log, MSGL_WARN);
+
int opt;
mp_read_option_raw(s->global, "access-references", &m_option_type_flag, &opt);
s->access_references = opt;
@@ -820,14 +829,13 @@ struct bstr stream_read_file(const char *filename, void *talloc_ctx,
struct mpv_global *global, int max_size)
{
struct bstr res = {0};
- char *fname = mp_get_user_path(NULL, global, filename);
- stream_t *s =
- stream_create(fname, STREAM_ORIGIN_DIRECT | STREAM_READ, NULL, global);
+ int flags = STREAM_ORIGIN_DIRECT | STREAM_READ | STREAM_LOCAL_FS_ONLY |
+ STREAM_LESS_NOISE;
+ stream_t *s = stream_create(filename, flags, NULL, global);
if (s) {
res = stream_read_complete(s, talloc_ctx, max_size);
free_stream(s);
}
- talloc_free(fname);
return res;
}