codec/substtml: prevent crash on empty attributes
authorFilip Roséen <filip@atch.se>
Mon, 19 Sep 2016 21:53:34 +0000 (23:53 +0200)
committerHugo Beauzée-Luyssen <hugo@beauzee.fr>
Mon, 19 Sep 2016 22:40:47 +0000 (00:40 +0200)
The previous implementation assumed that an attribute would always
have at least one specified region/style, which is not always the
case.

An attribute's value of zero-length, or one that contains only spaces,
would make strtok_r return NULL - resulting in undefined-behavior
further down the road.

In order to prevent these issues, an additional branch has been
introduced to warn if such attributes are found, and simply ignore
them.

fixes #17405

Signed-off-by: Hugo Beauzée-Luyssen <hugo@beauzee.fr>
modules/codec/substtml.c

index 8d5e3a3..2a45269 100644 (file)
@@ -264,6 +264,16 @@ static ttml_style_t* ParseTTMLStyle( decoder_t *p_dec, xml_reader_t* p_reader, c
                 }
 
                 char *token = strtok_r( value , " ", &tmp );
+
+                if( token == NULL )
+                {
+                    msg_Warn( p_dec, "No IDREF specified in attribute "
+                                     "'%s' on tag '%s', ignoring.", attr,
+                                     psz_node_name );
+                    free( value );
+                    continue;
+                }
+
                 ttml_style_t* p_style = FindTextStyle( p_dec, token );
                 if( p_style == NULL )
                 {