sdp: Check that fmt->oformat is non-null before accessing it

Message ID 1388756884-58880-1-git-send-email-martin@martin.st
State Committed
Commit 82b9799bb211ecd117171115e4a8b832c4942314
Headers show

Commit Message

Martin Storsjö Jan. 3, 2014, 1:48 p.m.
This avoids crashes when avserver tries to create an SDP, since
d77f4af.

CC: libav-stable@libav.org
---
 libavformat/sdp.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Luca Barbato Jan. 3, 2014, 2:50 p.m. | #1
On 03/01/14 14:48, Martin Storsjö wrote:
> This avoids crashes when avserver tries to create an SDP, since
> d77f4af.
> 
> CC: libav-stable@libav.org
> ---
>  libavformat/sdp.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 

It is probably ok, but when the oformat isn't set?

lu
Martin Storsjö Jan. 3, 2014, 3:44 p.m. | #2
On Fri, 3 Jan 2014, Luca Barbato wrote:

> On 03/01/14 14:48, Martin Storsjö wrote:
>> This avoids crashes when avserver tries to create an SDP, since
>> d77f4af.
>> 
>> CC: libav-stable@libav.org
>> ---
>>  libavformat/sdp.c |    2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>> 
>
> It is probably ok, but when the oformat isn't set?

Apparently avserver can call it like that. I guess avserver could/should 
be fixed as well, but this makes the code more robust at least.

// Martin

Patch

diff --git a/libavformat/sdp.c b/libavformat/sdp.c
index ec7e2f4..895b9d6 100644
--- a/libavformat/sdp.c
+++ b/libavformat/sdp.c
@@ -402,7 +402,7 @@  static char *sdp_write_media_attributes(char *buff, int size, AVCodecContext *c,
     switch (c->codec_id) {
         case AV_CODEC_ID_H264: {
             int mode = 1;
-            if (fmt && fmt->oformat->priv_class &&
+            if (fmt && fmt->oformat && fmt->oformat->priv_class &&
                 av_opt_flag_is_set(fmt->priv_data, "rtpflags", "h264_mode0"))
                 mode = 0;
             if (c->extradata_size) {