This is an automated email from the git hooks/post-receive script.

Git pushed a commit to branch master
in repository ffmpeg.

commit 394a7ff8ce9681d56e3f91559a79911d83beb8d3
Author:     Michael Niedermayer <[email protected]>
AuthorDate: Thu Feb 26 03:05:36 2026 +0100
Commit:     Michael Niedermayer <[email protected]>
CommitDate: Fri Mar 6 03:37:18 2026 +0100

    avformat: Add ff_format_check_set_url()
    
    Signed-off-by: Michael Niedermayer <[email protected]>
---
 libavformat/avformat.c | 32 ++++++++++++++++++++++++++++++++
 libavformat/internal.h | 10 ++++++++++
 2 files changed, 42 insertions(+)

diff --git a/libavformat/avformat.c b/libavformat/avformat.c
index 806f8dcab2..12af76c610 100644
--- a/libavformat/avformat.c
+++ b/libavformat/avformat.c
@@ -41,6 +41,7 @@
 #include "demux.h"
 #include "mux.h"
 #include "internal.h"
+#include "url.h"
 
 void ff_free_stream(AVStream **pst)
 {
@@ -868,6 +869,37 @@ void ff_format_set_url(AVFormatContext *s, char *url)
     s->url = url;
 }
 
+int ff_format_check_set_url(AVFormatContext *s, const char *url)
+{
+    URLComponents uc;
+    av_assert0(url);
+    char proto[64];
+
+    int ret = ff_url_decompose(&uc, url, NULL);
+    if (ret < 0)
+        return ret;
+    av_strlcpy(proto, uc.scheme, FFMIN(sizeof(proto), 
uc.url_component_end_scheme - uc.scheme));
+
+    if (s->protocol_whitelist && av_match_list(proto, s->protocol_whitelist, 
',') <= 0) {
+        av_log(s, AV_LOG_ERROR, "Protocol '%s' not on whitelist '%s'!\n", 
proto, s->protocol_whitelist);
+        return AVERROR(EINVAL);
+    }
+
+    if (s->protocol_blacklist && av_match_list(proto, s->protocol_blacklist, 
',') > 0) {
+        av_log(s, AV_LOG_ERROR, "Protocol '%s' on blacklist '%s'!\n", proto, 
s->protocol_blacklist);
+        return AVERROR(EINVAL);
+    }
+
+    url = av_strdup(url);
+    if (!url)
+        return AVERROR(ENOMEM);
+
+    av_freep(&s->url);
+    s->url = url;
+    return 0;
+}
+
+
 int ff_format_io_close(AVFormatContext *s, AVIOContext **pb)
 {
     int ret = 0;
diff --git a/libavformat/internal.h b/libavformat/internal.h
index 64452cce6e..89251b2460 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -630,6 +630,16 @@ int ff_bprint_to_codecpar_extradata(AVCodecParameters 
*par, struct AVBPrint *buf
  */
 void ff_format_set_url(AVFormatContext *s, char *url);
 
+/**
+ * Set AVFormatContext url field to a av_strdup of the provided pointer. The 
pointer must
+ * point to a valid string. The existing url field is freed if necessary.
+ *
+ * Checks protocol_whitelist/blacklist
+ *
+ * @returns a AVERROR code or non negative on success
+ */
+int ff_format_check_set_url(AVFormatContext *s, const char *url);
+
 /**
  * Return a positive value if the given url has one of the given
  * extensions, negative AVERROR on error, 0 otherwise.

_______________________________________________
ffmpeg-cvslog mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to