diff mbox series

[FFmpeg-devel] 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.

Message ID 3a73af48-1c9e-f475-d5b4-ada6db53b13c@gmail.com
State New
Headers show
Series [FFmpeg-devel] 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. | expand

Checks

Context Check Description
andriy/commit_msg_aarch64_jetson warning The first line of the commit message must start with a context terminated by a colon and a space, for example "lavu/opt: " or "doc: ".
andriy/commit_msg_armv7_RPi4 warning The first line of the commit message must start with a context terminated by a colon and a space, for example "lavu/opt: " or "doc: ".
andriy/make_aarch64_jetson success Make finished
andriy/make_fate_aarch64_jetson success Make fate finished
andriy/make_armv7_RPi4 success Make finished
andriy/make_fate_armv7_RPi4 success Make fate finished

Commit Message

Jonathan Baecker March 28, 2022, 4:14 p.m. UTC
Hello,

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

Regards

Jonathan
diff mbox series

Patch

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