* commit 'b1306823d0b3ae998c8e10ad832004eb13bdd93e':
check memory errors from av_strdup()
Conflicts:
avprobe.c
libavformat/matroskaenc.c
libavutil/opt.c
Merged-by: Michael Niedermayer <michaelni@gmx.at>
... | ... |
@@ -290,10 +290,14 @@ static int write_option(void *optctx, const OptionDef *po, const char *opt, |
290 | 290 |
if (po->flags & OPT_SPEC) { |
291 | 291 |
SpecifierOpt **so = dst; |
292 | 292 |
char *p = strchr(opt, ':'); |
293 |
+ char *str; |
|
293 | 294 |
|
294 | 295 |
dstcount = (int *)(so + 1); |
295 | 296 |
*so = grow_array(*so, sizeof(**so), dstcount, *dstcount + 1); |
296 |
- (*so)[*dstcount - 1].specifier = av_strdup(p ? p + 1 : ""); |
|
297 |
+ str = av_strdup(p ? p + 1 : ""); |
|
298 |
+ if (!str) |
|
299 |
+ return AVERROR(ENOMEM); |
|
300 |
+ (*so)[*dstcount - 1].specifier = str; |
|
297 | 301 |
dst = &(*so)[*dstcount - 1].u; |
298 | 302 |
} |
299 | 303 |
|
... | ... |
@@ -301,6 +305,8 @@ static int write_option(void *optctx, const OptionDef *po, const char *opt, |
301 | 301 |
char *str; |
302 | 302 |
str = av_strdup(arg); |
303 | 303 |
av_freep(dst); |
304 |
+ if (!str) |
|
305 |
+ return AVERROR(ENOMEM); |
|
304 | 306 |
*(char **)dst = str; |
305 | 307 |
} else if (po->flags & OPT_BOOL || po->flags & OPT_INT) { |
306 | 308 |
*(int *)dst = parse_number_or_die(opt, arg, OPT_INT64, INT_MIN, INT_MAX); |
... | ... |
@@ -1816,6 +1822,8 @@ int show_help(void *optctx, const char *opt, const char *arg) |
1816 | 1816 |
av_log_set_callback(log_callback_help); |
1817 | 1817 |
|
1818 | 1818 |
topic = av_strdup(arg ? arg : ""); |
1819 |
+ if (!topic) |
|
1820 |
+ return AVERROR(ENOMEM); |
|
1819 | 1821 |
par = strchr(topic, '='); |
1820 | 1822 |
if (par) |
1821 | 1823 |
*par++ = 0; |
... | ... |
@@ -231,6 +231,8 @@ static int opt_map(void *optctx, const char *opt, const char *arg) |
231 | 231 |
arg++; |
232 | 232 |
} |
233 | 233 |
map = av_strdup(arg); |
234 |
+ if (!map) |
|
235 |
+ return AVERROR(ENOMEM); |
|
234 | 236 |
|
235 | 237 |
/* parse sync stream first, just pick first matching stream */ |
236 | 238 |
if (sync = strchr(map, ',')) { |
... | ... |
@@ -1084,13 +1084,16 @@ static int mkv_write_chapters(AVFormatContext *s) |
1084 | 1084 |
return 0; |
1085 | 1085 |
} |
1086 | 1086 |
|
1087 |
-static void mkv_write_simpletag(AVIOContext *pb, AVDictionaryEntry *t) |
|
1087 |
+static int mkv_write_simpletag(AVIOContext *pb, AVDictionaryEntry *t) |
|
1088 | 1088 |
{ |
1089 | 1089 |
uint8_t *key = av_strdup(t->key); |
1090 | 1090 |
uint8_t *p = key; |
1091 | 1091 |
const uint8_t *lang = NULL; |
1092 | 1092 |
ebml_master tag; |
1093 | 1093 |
|
1094 |
+ if (!key) |
|
1095 |
+ return AVERROR(ENOMEM); |
|
1096 |
+ |
|
1094 | 1097 |
if ((p = strrchr(p, '-')) && |
1095 | 1098 |
(lang = av_convert_lang_to(p + 1, AV_LANG_ISO639_2_BIBL))) |
1096 | 1099 |
*p = 0; |
... | ... |
@@ -1112,6 +1115,7 @@ static void mkv_write_simpletag(AVIOContext *pb, AVDictionaryEntry *t) |
1112 | 1112 |
end_ebml_master(pb, tag); |
1113 | 1113 |
|
1114 | 1114 |
av_freep(&key); |
1115 |
+ return 0; |
|
1115 | 1116 |
} |
1116 | 1117 |
|
1117 | 1118 |
static int mkv_write_tag(AVFormatContext *s, AVDictionary *m, unsigned int elementid, |
... | ... |
@@ -1135,11 +1139,15 @@ static int mkv_write_tag(AVFormatContext *s, AVDictionary *m, unsigned int eleme |
1135 | 1135 |
put_ebml_uint(s->pb, elementid, uid); |
1136 | 1136 |
end_ebml_master(s->pb, targets); |
1137 | 1137 |
|
1138 |
- while ((t = av_dict_get(m, "", t, AV_DICT_IGNORE_SUFFIX))) |
|
1138 |
+ while ((t = av_dict_get(m, "", t, AV_DICT_IGNORE_SUFFIX))) { |
|
1139 | 1139 |
if (av_strcasecmp(t->key, "title") && |
1140 | 1140 |
av_strcasecmp(t->key, "stereo_mode") && |
1141 |
- av_strcasecmp(t->key, "encoding_tool")) |
|
1142 |
- mkv_write_simpletag(s->pb, t); |
|
1141 |
+ av_strcasecmp(t->key, "encoding_tool")) { |
|
1142 |
+ ret = mkv_write_simpletag(s->pb, t); |
|
1143 |
+ if (ret < 0) |
|
1144 |
+ return ret; |
|
1145 |
+ } |
|
1146 |
+ } |
|
1143 | 1147 |
|
1144 | 1148 |
end_ebml_master(s->pb, tag); |
1145 | 1149 |
return 0; |
... | ... |
@@ -162,7 +162,7 @@ static int set_string(void *obj, const AVOption *o, const char *val, uint8_t **d |
162 | 162 |
{ |
163 | 163 |
av_freep(dst); |
164 | 164 |
*dst = av_strdup(val); |
165 |
- return 0; |
|
165 |
+ return *dst ? 0 : AVERROR(ENOMEM); |
|
166 | 166 |
} |
167 | 167 |
|
168 | 168 |
#define DEFAULT_NUMVAL(opt) ((opt->type == AV_OPT_TYPE_INT64 || \ |
... | ... |
@@ -711,7 +711,7 @@ int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val) |
711 | 711 |
*out_val = av_strdup(*(uint8_t**)dst); |
712 | 712 |
else |
713 | 713 |
*out_val = av_strdup(""); |
714 |
- return 0; |
|
714 |
+ return *out_val ? 0 : AVERROR(ENOMEM); |
|
715 | 715 |
case AV_OPT_TYPE_BINARY: |
716 | 716 |
len = *(int*)(((uint8_t *)dst) + sizeof(uint8_t *)); |
717 | 717 |
if ((uint64_t)len*2 + 1 > INT_MAX) |
... | ... |
@@ -757,7 +757,7 @@ int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val) |
757 | 757 |
if (ret >= sizeof(buf)) |
758 | 758 |
return AVERROR(EINVAL); |
759 | 759 |
*out_val = av_strdup(buf); |
760 |
- return 0; |
|
760 |
+ return *out_val ? 0 : AVERROR(ENOMEM); |
|
761 | 761 |
} |
762 | 762 |
|
763 | 763 |
static int get_number(void *obj, const char *name, const AVOption **o_out, double *num, int *den, int64_t *intnum, |