From: Rashad Tatum <tatum.rashad@gmail.com> To: ffmpeg-devel@ffmpeg.org Cc: Rashad Tatum <tatum.rashad@gmail.com> Subject: [FFmpeg-devel] [PATCH v3] libavformat/rtsp: Change ff_sdp_parse and sdp_parse_line to handle memory alloc errors Date: Sat, 1 Mar 2025 16:15:02 -0500 Message-ID: <20250301211522.2061581-1-tatum.rashad@gmail.com> (raw) for RTSPStream and RTSPSource --- libavformat/rtsp.c | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c index 25a7602832..bf5db93e44 100644 --- a/libavformat/rtsp.c +++ b/libavformat/rtsp.c @@ -423,7 +423,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; @@ -441,18 +441,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 == '/') { @@ -500,11 +500,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,15 +660,15 @@ 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); @@ -677,7 +677,7 @@ static void sdp_parse_line(AVFormatContext *s, SDPParseState *s1, rtsp_src = av_mallocz(sizeof(*rtsp_src)); if (!rtsp_src) { av_freep(&dest_addr); - return; + return AVERROR(ENOMEM); } av_strlcpy(rtsp_src->dest_addr, dest_addr, sizeof(rtsp_src->dest_addr)); get_word(rtsp_src->src_addr, sizeof(rtsp_src->src_addr), &p); @@ -716,12 +716,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], sdp_ip_str[50], *q; bool parsed_first_media_desc = false; SDPParseState sdp_parse_state = { { 0 } }, *s1 = &sdp_parse_state; @@ -762,7 +764,10 @@ int ff_sdp_parse(AVFormatContext *s, const char *content) } *q = '\0'; - sdp_parse_line(s, s1, letter, buf); + err = sdp_parse_line(s, s1, letter, buf); + if (err < 0 ) + return err; + if(letter == 'm') parsed_first_media_desc = true; -- 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 21:15 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=20250301211522.2061581-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