From: Andre Noll Date: Mon, 9 Aug 2021 18:05:10 +0000 (+0200) Subject: mp4: Use para_strdup(). X-Git-Tag: v0.7.1~7^2~126 X-Git-Url: http://git.tue.mpg.de/?a=commitdiff_plain;h=39a3eb513e1a98a3a0cc54c38dacb89451ffe88e;p=paraslash.git mp4: Use para_strdup(). Like malloc(), strdup() may fail. The current code does not always check that. Using the paraslash wrapper avoids the issue and has the additional benefit that para_strdup(NULL) does not segfault. --- diff --git a/mp4.c b/mp4.c index 9b09a8f4..8f1ddec2 100644 --- a/mp4.c +++ b/mp4.c @@ -773,25 +773,15 @@ static int32_t mp4ff_tag_add_field(mp4ff_metadata_t * tags, const char *item, free(backup); return 0; } else { - tags->tags[tags->count].item = strdup(item); + tags->tags[tags->count].item = para_strdup(item); tags->tags[tags->count].len = len; if (len >= 0) { tags->tags[tags->count].value = para_malloc(len + 1); memcpy(tags->tags[tags->count].value, value, len); tags->tags[tags->count].value[len] = 0; } else { - tags->tags[tags->count].value = strdup(value); + tags->tags[tags->count].value = para_strdup(value); } - - if (!tags->tags[tags->count].item || !tags->tags[tags->count].value) { - free(tags->tags[tags->count].item); - free(tags->tags[tags->count].value); - tags->tags[tags->count].item = NULL; - tags->tags[tags->count].value = NULL; - tags->tags[tags->count].len = 0; - return 0; - } - tags->count++; return 1; } @@ -958,8 +948,7 @@ static int32_t mp4ff_set_metadata_name(const uint8_t atom_type, char **name) break; } - *name = strdup(tag_names[tag_idx]); - + *name = para_strdup(tag_names[tag_idx]); return 0; } @@ -1475,8 +1464,8 @@ int32_t mp4ff_meta_get_by_index(const mp4ff_t * f, uint32_t index, *value = NULL; return 0; } else { - *item = strdup(f->tags.tags[index].item); - *value = strdup(f->tags.tags[index].value); + *item = para_strdup(f->tags.tags[index].item); + *value = para_strdup(f->tags.tags[index].value); return 1; } } @@ -2165,7 +2154,7 @@ static int32_t mp4ff_meta_find_by_name(const mp4ff_t * f, const char *item, for (i = 0; i < f->tags.count; i++) { if (!stricmp(f->tags.tags[i].item, item)) { - *value = strdup(f->tags.tags[i].value); + *value = para_strdup(f->tags.tags[i].value); return 1; } }