Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Rashad Tatum <tatum.rashad@gmail.com>
To: ffmpeg-devel@ffmpeg.org
Cc: Rashad Tatum <tatum.rashad@gmail.com>
Subject: [FFmpeg-devel] [PATCH v4] libavformat/rtsp: Change ff_sdp_parse and sdp_parse_line to handle memory alloc errors
Date: Sat,  1 Mar 2025 17:07:50 -0500
Message-ID: <20250301220815.2091788-1-tatum.rashad@gmail.com> (raw)

for RTSPStream and RTSPSource
---
 libavformat/rtsp.c | 32 ++++++++++++++++++--------------
 1 file changed, 18 insertions(+), 14 deletions(-)

diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c
index 5ea471b40c..d16fd24ade 100644
--- a/libavformat/rtsp.c
+++ b/libavformat/rtsp.c
@@ -418,7 +418,7 @@ static void parse_fmtp(AVFormatContext *s, RTSPState *rt,
     }
 }
 
-static void sdp_parse_line(AVFormatContext *s, SDPParseState *s1,
+static int sdp_parse_line(AVFormatContext *s, SDPParseState *s1,
                            int letter, const char *buf)
 {
     RTSPState *rt = s->priv_data;
@@ -436,18 +436,18 @@ static void sdp_parse_line(AVFormatContext *s, SDPParseState *s1,
 
     p = buf;
     if (s1->skip_media && letter != 'm')
-        return;
+        return 0;
     switch (letter) {
     case 'c':
         get_word(buf1, sizeof(buf1), &p);
         if (strcmp(buf1, "IN") != 0)
-            return;
+            break;
         get_word(buf1, sizeof(buf1), &p);
         if (strcmp(buf1, "IP4") && strcmp(buf1, "IP6"))
-            return;
+            break;
         get_word_sep(buf1, sizeof(buf1), "/", &p);
         if (get_sockaddr(s, buf1, &sdp_ip))
-            return;
+            break;
         ttl = 16;
         if (*p == '/') {
             p++;
@@ -493,11 +493,11 @@ static void sdp_parse_line(AVFormatContext *s, SDPParseState *s1,
             rt->nb_rtsp_streams >= s->max_streams
         ) {
             s1->skip_media = 1;
-            return;
+            break;
         }
         rtsp_st = av_mallocz(sizeof(RTSPStream));
         if (!rtsp_st)
-            return;
+            return AVERROR(ENOMEM);
         rtsp_st->stream_index = -1;
         dynarray_add(&rt->rtsp_streams, &rt->nb_rtsp_streams, rtsp_st);
 
@@ -545,7 +545,7 @@ static void sdp_parse_line(AVFormatContext *s, SDPParseState *s1,
         } else {
             st = avformat_new_stream(s, NULL);
             if (!st)
-                return;
+                break;
             st->id = rt->nb_rtsp_streams - 1;
             rtsp_st->stream_index = st->index;
             st->codecpar->codec_type = codec_type;
@@ -660,22 +660,22 @@ static void sdp_parse_line(AVFormatContext *s, SDPParseState *s1,
             int exclude = 0;
             get_word(buf1, sizeof(buf1), &p);
             if (strcmp(buf1, "incl") && strcmp(buf1, "excl"))
-                return;
+                break;
             exclude = !strcmp(buf1, "excl");
 
             get_word(buf1, sizeof(buf1), &p);
             if (strcmp(buf1, "IN") != 0)
-                return;
+                break;
             get_word(buf1, sizeof(buf1), &p);
             if (strcmp(buf1, "IP4") && strcmp(buf1, "IP6") && strcmp(buf1, "*"))
-                return;
+                break;
             // not checking that the destination address actually matches or is wildcard
             get_word(buf1, sizeof(buf1), &p);
 
             while (*p != '\0') {
                 rtsp_src = av_mallocz(sizeof(*rtsp_src));
                 if (!rtsp_src)
-                    return;
+                    return AVERROR(ENOMEM);
                 get_word(rtsp_src->addr, sizeof(rtsp_src->addr), &p);
                 if (exclude) {
                     if (s->nb_streams == 0) {
@@ -711,12 +711,14 @@ static void sdp_parse_line(AVFormatContext *s, SDPParseState *s1,
         }
         break;
     }
+
+    return 0;
 }
 
 int ff_sdp_parse(AVFormatContext *s, const char *content)
 {
     const char *p;
-    int letter, i;
+    int letter, i, err;
     char buf[SDP_MAX_SIZE], *q;
     SDPParseState sdp_parse_state = { { 0 } }, *s1 = &sdp_parse_state;
 
@@ -738,7 +740,9 @@ int ff_sdp_parse(AVFormatContext *s, const char *content)
             p++;
         }
         *q = '\0';
-        sdp_parse_line(s, s1, letter, buf);
+        err = sdp_parse_line(s, s1, letter, buf);
+        if(err < 0)
+            return AVERROR(ENOMEM);
     next_line:
         while (*p != '\n' && *p != '\0')
             p++;
-- 
2.48.1

_______________________________________________
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".

                 reply	other threads:[~2025-03-01 22:08 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250301220815.2091788-1-tatum.rashad@gmail.com \
    --to=tatum.rashad@gmail.com \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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