From f70995cc9b435f0d26ee3e6a54e4875f6fde8e20 Mon Sep 17 00:00:00 2001 From: Guido Cella Date: Sun, 20 Jun 2021 17:10:39 +0200 Subject: player: fix segfault Commit 029ff10 added a goto statement which skipped initializing the `lang' variable. This could crash depending on compiler optimizations and other factors: if the lang bstr pointer happened to end up NULL (which is apparently the case with most compilers) then it's validly empty, but if it pointed to a random and incorrect memory address then it crashed. The crash was observed when mpv was compiled using gcc 10.2 with optimizations enabled, and affected some third party Windows builds. This commit ensures the goto doesn't skip the initialization. Thanks to votemp for figuring this out. Fixes #8922. --- player/external_files.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/player/external_files.c b/player/external_files.c index 449e62d623..0e3fad73f7 100644 --- a/player/external_files.c +++ b/player/external_files.c @@ -224,10 +224,9 @@ static void append_dir_subtitles(struct mpv_global *global, struct MPOpts *opts, (type != STREAM_VIDEO || (fuzz != 1 && bstrcmp(dename, f_fname) != 0))) prio |= 32; // exact movie name match + bstr lang = {0}; if (type == STREAM_VIDEO) goto cover_art; - - bstr lang = {0}; if (bstr_startswith(tmp_fname_trim, f_fname_trim)) { int start = 0; lang = guess_lang_from_filename(tmp_fname_trim, &start); -- cgit v1.2.3