Fix segfault in add_cc_sub_text and initialize to NULL in init_encoder (#950)

This commit adds some checks to avoid segmentation faults.

* In `add_cc_sub_text()`, strdup will cause a segfault if we duplicate an
  empty string.

* In `init_encoder()`, initialize pointer fields to NULL to avoid random
  addressing so we can avoid illegal memory accessing and segfaults in
  other places.
This commit is contained in:
Saurabh Shah
2018-03-06 03:25:01 +05:30
committed by Carlos Fernandez Sanz
parent a0e7ddd632
commit f46e3dcfc2
2 changed files with 3 additions and 0 deletions

View File

@@ -70,6 +70,8 @@ void freep(void *arg)
int add_cc_sub_text(struct cc_subtitle *sub, char *str, LLONG start_time,
LLONG end_time, char *info, char *mode, enum ccx_encoding_type e_type)
{
if (str == NULL || strlen(str) == 0)
return 0;
if (sub->nb_data)
{
for(;sub->next;sub = sub->next);

View File

@@ -1038,6 +1038,7 @@ struct encoder_ctx *init_encoder(struct encoder_cfg *opt)
ctx->segment_last_key_frame = 0;
ctx->nospupngocr = opt->nospupngocr;
ctx->prev = NULL;
return ctx;
}