Skip to content

Commit

Permalink
Avoid segmentation faults in dinit_encoder() and add_cc_sub_text()
Browse files Browse the repository at this point in the history
This commit adds some checks to avoid segmentation faults.

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

* In `dinit_encoder()`, accessing memory that doesn't exist will cause a
  segfault in case of processing hardsubs.
  • Loading branch information
saurabhshah0410 committed Mar 3, 2018
1 parent a0e7ddd commit a1dc19d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/lib_ccx/ccx_common_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/lib_ccx/ccx_encoders_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,8 @@ void dinit_encoder(struct encoder_ctx **arg, LLONG current_fts)
write_subtitle_file_footer(ctx, ctx->out + i);
}

free_encoder_context(ctx->prev);
if(!ccx_options.hardsubx) // Don't free ctx->prev in case of hardsubx to avoid segfault
free_encoder_context(ctx->prev);
dinit_output_ctx(ctx);
freep(&ctx->subline);
freep(&ctx->buffer);
Expand Down

0 comments on commit a1dc19d

Please sign in to comment.