Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH] libavformat/rtmp: Adding a flag to give user the option to have ffmpeg fail instead of warn when mismatches are found in rtmp url stream or application names.
@ 2022-03-28 16:14 jb
  0 siblings, 0 replies; 2+ messages in thread
From: jb @ 2022-03-28 16:14 UTC (permalink / raw)
  To: ffmpeg-devel

[-- Attachment #1: Type: text/plain, Size: 121 bytes --]

Hello,

this patch was originally from William Martin, I just adapt it to the 
newest ffmpeg version.

Regards

Jonathan

[-- Attachment #2: 0001-Adding-a-flag-to-give-user-the-option-to-have-ffmpeg.patch --]
[-- Type: text/x-patch, Size: 4883 bytes --]

From 89b441ce47614035a545da1a7ce46c53ccf165e5 Mon Sep 17 00:00:00 2001
From: jb-alvarado <jonbae77@gmail.com>
Date: Mon, 28 Mar 2022 17:07:57 +0200
Subject: [PATCH] Adding a flag to give user the option to have ffmpeg fail
 instead of warn when mismatches are found in rtmp url stream or application
 names.

from original:
https://patchwork.ffmpeg.org/project/ffmpeg/patch/20190925185708.70924-1-unique.will.martin@gmail.com/
---
 libavformat/librtmp.c   |  2 ++
 libavformat/rtmpproto.c | 28 ++++++++++++++++++++++------
 2 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/libavformat/librtmp.c b/libavformat/librtmp.c
index 43013e4..00b4966 100644
--- a/libavformat/librtmp.c
+++ b/libavformat/librtmp.c
@@ -52,6 +52,7 @@ typedef struct LibRTMPContext {
     int live;
     char *temp_filename;
     int buffer_size;
+    bool strict_paths;
 } LibRTMPContext;

 static void rtmp_log(int level, const char *fmt, va_list args)
@@ -333,6 +334,7 @@ static const AVOption options[] = {
     {"rtmp_swfurl", "URL of the SWF player. By default no value will be sent", OFFSET(swfurl), AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0, DEC|ENC},
     {"rtmp_swfverify", "URL to player swf file, compute hash/size automatically. (unimplemented)", OFFSET(swfverify), AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0, DEC},
     {"rtmp_tcurl", "URL of the target stream. Defaults to proto://host[:port]/app.", OFFSET(tcurl), AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0, DEC|ENC},
+    {"rtmp_strict_paths", "Error instead of warn for mismatch on stream or application path in url", OFFSET(strict_paths), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, DEC},
 #if CONFIG_NETWORK
     {"rtmp_buffer_size", "set buffer size in bytes", OFFSET(buffer_size), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, DEC|ENC },
 #endif
diff --git a/libavformat/rtmpproto.c b/libavformat/rtmpproto.c
index f97e3c3..34433ed 100644
--- a/libavformat/rtmpproto.c
+++ b/libavformat/rtmpproto.c
@@ -132,6 +132,7 @@ typedef struct RTMPContext {
     char          auth_params[500];
     int           do_reconnect;
     int           auth_tried;
+    int           strict_paths;               ///< If true, enforce strict string matching on rtmp stream and application
 } RTMPContext;

 #define PLAYER_KEY_OPEN_PART_LEN 30   ///< length of partial key used for first client digest signing
@@ -480,9 +481,16 @@ static int read_connect(URLContext *s, RTMPContext *rt)
                                  "app", tmpstr, sizeof(tmpstr));
     if (ret)
         av_log(s, AV_LOG_WARNING, "App field not found in connect\n");
-    if (!ret && strcmp(tmpstr, rt->app))
-        av_log(s, AV_LOG_WARNING, "App field don't match up: %s <-> %s\n",
-               tmpstr, rt->app);
+    if (!ret && strcmp(tmpstr, rt->app)) {
+        if (rt->strict_paths) {
+            av_log(s, AV_LOG_ERROR, "App field don't match up: %s <-> %s. "
+               "Exiting since rtmp_strict_paths provided\n", tmpstr, rt->app);
+            return AVERROR(EIO);
+        } else {
+            av_log(s, AV_LOG_WARNING, "App field don't match up: %s <-> %s\n",
+                tmpstr, rt->app);
+        }
+    }
     ff_rtmp_packet_destroy(&pkt);

     // Send Window Acknowledgement Size (as defined in specification)
@@ -1947,9 +1955,16 @@ static int send_invoke_response(URLContext *s, RTMPPacket *pkt)
                 pchar = s->filename;
             }
             pchar++;
-            if (strcmp(pchar, filename))
-                av_log(s, AV_LOG_WARNING, "Unexpected stream %s, expecting"
-                       " %s\n", filename, pchar);
+            if (strcmp(pchar, filename)) {
+                if (rt->strict_paths) {
+                    av_log(s, AV_LOG_ERROR, "Unexpected stream %s, expecting %s. "
+                        "Exiting since rtmp_strict_paths provided.\n", filename, pchar);
+                    return AVERROR(EIO);
+                } else {
+                    av_log(s, AV_LOG_WARNING, "Unexpected stream %s, expecting"
+                        " %s\n", filename, pchar);
+                }
+            }
         }
         rt->state = STATE_RECEIVING;
     }
@@ -3119,6 +3134,7 @@ static const AVOption rtmp_options[] = {
     {"listen",      "Listen for incoming rtmp connections", OFFSET(listen), AV_OPT_TYPE_INT, {.i64 = 0}, INT_MIN, INT_MAX, DEC, "rtmp_listen" },
     {"tcp_nodelay", "Use TCP_NODELAY to disable Nagle's algorithm", OFFSET(tcp_nodelay), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, DEC|ENC},
     {"timeout", "Maximum timeout (in seconds) to wait for incoming connections. -1 is infinite. Implies -rtmp_listen 1",  OFFSET(listen_timeout), AV_OPT_TYPE_INT, {.i64 = -1}, INT_MIN, INT_MAX, DEC, "rtmp_listen" },
+    {"rtmp_strict_paths", "Error instead of warn for mismatch on stream or application path in url", OFFSET(strict_paths), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, DEC},
     { NULL },
 };

--
2.35.1


[-- Attachment #3: Type: text/plain, Size: 251 bytes --]

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 2+ messages in thread
* [FFmpeg-devel] [PATCH] libavformat/rtmp: Adding a flag to give user the option to have ffmpeg fail instead of warn when mismatches are found in rtmp url stream or application names.
@ 2022-03-28 16:13 jb
  0 siblings, 0 replies; 2+ messages in thread
From: jb @ 2022-03-28 16:13 UTC (permalink / raw)
  To: ffmpeg-devel

[-- Attachment #1: Type: text/plain, Size: 121 bytes --]

Hello,

this patch was originally from William Martin, I just adapt it to the 
newest ffmpeg version.

Regards

Jonathan

[-- Attachment #2: 0001-Adding-a-flag-to-give-user-the-option-to-have-ffmpeg.patch --]
[-- Type: text/x-patch, Size: 4883 bytes --]

From 89b441ce47614035a545da1a7ce46c53ccf165e5 Mon Sep 17 00:00:00 2001
From: jb-alvarado <jonbae77@gmail.com>
Date: Mon, 28 Mar 2022 17:07:57 +0200
Subject: [PATCH] Adding a flag to give user the option to have ffmpeg fail
 instead of warn when mismatches are found in rtmp url stream or application
 names.

from original:
https://patchwork.ffmpeg.org/project/ffmpeg/patch/20190925185708.70924-1-unique.will.martin@gmail.com/
---
 libavformat/librtmp.c   |  2 ++
 libavformat/rtmpproto.c | 28 ++++++++++++++++++++++------
 2 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/libavformat/librtmp.c b/libavformat/librtmp.c
index 43013e4..00b4966 100644
--- a/libavformat/librtmp.c
+++ b/libavformat/librtmp.c
@@ -52,6 +52,7 @@ typedef struct LibRTMPContext {
     int live;
     char *temp_filename;
     int buffer_size;
+    bool strict_paths;
 } LibRTMPContext;

 static void rtmp_log(int level, const char *fmt, va_list args)
@@ -333,6 +334,7 @@ static const AVOption options[] = {
     {"rtmp_swfurl", "URL of the SWF player. By default no value will be sent", OFFSET(swfurl), AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0, DEC|ENC},
     {"rtmp_swfverify", "URL to player swf file, compute hash/size automatically. (unimplemented)", OFFSET(swfverify), AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0, DEC},
     {"rtmp_tcurl", "URL of the target stream. Defaults to proto://host[:port]/app.", OFFSET(tcurl), AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0, DEC|ENC},
+    {"rtmp_strict_paths", "Error instead of warn for mismatch on stream or application path in url", OFFSET(strict_paths), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, DEC},
 #if CONFIG_NETWORK
     {"rtmp_buffer_size", "set buffer size in bytes", OFFSET(buffer_size), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, DEC|ENC },
 #endif
diff --git a/libavformat/rtmpproto.c b/libavformat/rtmpproto.c
index f97e3c3..34433ed 100644
--- a/libavformat/rtmpproto.c
+++ b/libavformat/rtmpproto.c
@@ -132,6 +132,7 @@ typedef struct RTMPContext {
     char          auth_params[500];
     int           do_reconnect;
     int           auth_tried;
+    int           strict_paths;               ///< If true, enforce strict string matching on rtmp stream and application
 } RTMPContext;

 #define PLAYER_KEY_OPEN_PART_LEN 30   ///< length of partial key used for first client digest signing
@@ -480,9 +481,16 @@ static int read_connect(URLContext *s, RTMPContext *rt)
                                  "app", tmpstr, sizeof(tmpstr));
     if (ret)
         av_log(s, AV_LOG_WARNING, "App field not found in connect\n");
-    if (!ret && strcmp(tmpstr, rt->app))
-        av_log(s, AV_LOG_WARNING, "App field don't match up: %s <-> %s\n",
-               tmpstr, rt->app);
+    if (!ret && strcmp(tmpstr, rt->app)) {
+        if (rt->strict_paths) {
+            av_log(s, AV_LOG_ERROR, "App field don't match up: %s <-> %s. "
+               "Exiting since rtmp_strict_paths provided\n", tmpstr, rt->app);
+            return AVERROR(EIO);
+        } else {
+            av_log(s, AV_LOG_WARNING, "App field don't match up: %s <-> %s\n",
+                tmpstr, rt->app);
+        }
+    }
     ff_rtmp_packet_destroy(&pkt);

     // Send Window Acknowledgement Size (as defined in specification)
@@ -1947,9 +1955,16 @@ static int send_invoke_response(URLContext *s, RTMPPacket *pkt)
                 pchar = s->filename;
             }
             pchar++;
-            if (strcmp(pchar, filename))
-                av_log(s, AV_LOG_WARNING, "Unexpected stream %s, expecting"
-                       " %s\n", filename, pchar);
+            if (strcmp(pchar, filename)) {
+                if (rt->strict_paths) {
+                    av_log(s, AV_LOG_ERROR, "Unexpected stream %s, expecting %s. "
+                        "Exiting since rtmp_strict_paths provided.\n", filename, pchar);
+                    return AVERROR(EIO);
+                } else {
+                    av_log(s, AV_LOG_WARNING, "Unexpected stream %s, expecting"
+                        " %s\n", filename, pchar);
+                }
+            }
         }
         rt->state = STATE_RECEIVING;
     }
@@ -3119,6 +3134,7 @@ static const AVOption rtmp_options[] = {
     {"listen",      "Listen for incoming rtmp connections", OFFSET(listen), AV_OPT_TYPE_INT, {.i64 = 0}, INT_MIN, INT_MAX, DEC, "rtmp_listen" },
     {"tcp_nodelay", "Use TCP_NODELAY to disable Nagle's algorithm", OFFSET(tcp_nodelay), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, DEC|ENC},
     {"timeout", "Maximum timeout (in seconds) to wait for incoming connections. -1 is infinite. Implies -rtmp_listen 1",  OFFSET(listen_timeout), AV_OPT_TYPE_INT, {.i64 = -1}, INT_MIN, INT_MAX, DEC, "rtmp_listen" },
+    {"rtmp_strict_paths", "Error instead of warn for mismatch on stream or application path in url", OFFSET(strict_paths), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, DEC},
     { NULL },
 };

--
2.35.1


[-- Attachment #3: Type: text/plain, Size: 251 bytes --]

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-03-28 16:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-28 16:14 [FFmpeg-devel] [PATCH] libavformat/rtmp: Adding a flag to give user the option to have ffmpeg fail instead of warn when mismatches are found in rtmp url stream or application names jb
  -- strict thread matches above, loose matches on Subject: below --
2022-03-28 16:13 jb

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git