avformat/sdp: Check before appending ","

Found by reviewing code related to CID1500301 String not null terminated

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
(cherry picked from commit 5b82852519)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
This commit is contained in:
Michael Niedermayer 2024-05-08 04:07:40 +02:00
parent 7d21ba839b
commit ef800a7072
No known key found for this signature in database
GPG Key ID: B18E8928B3948D64
1 changed files with 3 additions and 0 deletions

View File

@ -195,6 +195,8 @@ static char *extradata2psets(AVFormatContext *s, AVCodecParameters *par)
continue; continue;
} }
if (p != (psets + strlen(pset_string))) { if (p != (psets + strlen(pset_string))) {
if (p - psets >= MAX_PSET_SIZE)
goto fail_in_loop;
*p = ','; *p = ',';
p++; p++;
} }
@ -204,6 +206,7 @@ static char *extradata2psets(AVFormatContext *s, AVCodecParameters *par)
} }
if (!av_base64_encode(p, MAX_PSET_SIZE - (p - psets), r, r1 - r)) { if (!av_base64_encode(p, MAX_PSET_SIZE - (p - psets), r, r1 - r)) {
av_log(s, AV_LOG_ERROR, "Cannot Base64-encode %"PTRDIFF_SPECIFIER" %"PTRDIFF_SPECIFIER"!\n", MAX_PSET_SIZE - (p - psets), r1 - r); av_log(s, AV_LOG_ERROR, "Cannot Base64-encode %"PTRDIFF_SPECIFIER" %"PTRDIFF_SPECIFIER"!\n", MAX_PSET_SIZE - (p - psets), r1 - r);
fail_in_loop:
av_free(psets); av_free(psets);
av_free(tmpbuf); av_free(tmpbuf);