From b1306823d0b3ae998c8e10ad832004eb13bdd93e Mon Sep 17 00:00:00 2001 From: Vittorio Giovara Date: Wed, 17 Dec 2014 14:53:45 +0100 Subject: check memory errors from av_strdup() --- libavformat/matroskaenc.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'libavformat/matroskaenc.c') diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index 8a7cfa128f..1d55b6629a 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -936,13 +936,16 @@ static int mkv_write_chapters(AVFormatContext *s) return 0; } -static void mkv_write_simpletag(AVIOContext *pb, AVDictionaryEntry *t) +static int mkv_write_simpletag(AVIOContext *pb, AVDictionaryEntry *t) { uint8_t *key = av_strdup(t->key); uint8_t *p = key; const uint8_t *lang = NULL; ebml_master tag; + if (!key) + return AVERROR(ENOMEM); + if ((p = strrchr(p, '-')) && (lang = av_convert_lang_to(p + 1, AV_LANG_ISO639_2_BIBL))) *p = 0; @@ -964,6 +967,7 @@ static void mkv_write_simpletag(AVIOContext *pb, AVDictionaryEntry *t) end_ebml_master(pb, tag); av_freep(&key); + return 0; } static int mkv_write_tag(AVFormatContext *s, AVDictionary *m, unsigned int elementid, @@ -987,10 +991,14 @@ static int mkv_write_tag(AVFormatContext *s, AVDictionary *m, unsigned int eleme put_ebml_uint(s->pb, elementid, uid); end_ebml_master(s->pb, targets); - while ((t = av_dict_get(m, "", t, AV_DICT_IGNORE_SUFFIX))) + while ((t = av_dict_get(m, "", t, AV_DICT_IGNORE_SUFFIX))) { if (av_strcasecmp(t->key, "title") && - av_strcasecmp(t->key, "encoding_tool")) - mkv_write_simpletag(s->pb, t); + av_strcasecmp(t->key, "encoding_tool")) { + ret = mkv_write_simpletag(s->pb, t); + if (ret < 0) + return ret; + } + } end_ebml_master(s->pb, tag); return 0; -- cgit v1.2.3