Resolve use-after-free in cf_CopyFile

==92396==ERROR: AddressSanitizer: heap-use-after-free on address 0x504000034ae8 at pc 0x000000f86037 bp 0x7fffffffa9d0 sp 0x7fffffffa9c8
READ of size 4 at 0x504000034ae8 thread T0
    f0 cf_CopyFile(std::filesystem::__cxx11::path const&, std::filesystem::__cxx11::path const&, int) $GIT/cfile/cfile.cpp:856
    f1 _extractscript(char*, char*) $GIT/Descent3/OsirisLoadandBind.cpp:3109
    f2 Osiris_ExtractScriptsFromHog(int, bool) $GIT/Descent3/OsirisLoadandBind.cpp:3185
    f3 InitIOSystems $GIT/Descent3/init.cpp:1549
    f4 InitD3Systems1(bool) $GIT/Descent3/init.cpp:1827
This commit is contained in:
Jan Engelhardt 2024-08-29 23:35:24 +02:00
parent 2db85ca6ec
commit 571c0199e9

View File

@ -851,9 +851,10 @@ bool cf_CopyFile(const std::filesystem::path &dest, const std::filesystem::path
// c=cf_ReadByte (infile);
// cf_WriteByte (outfile,c);
}
bool nlo = !infile->lib_offset;
cfclose(infile);
cfclose(outfile);
if (!infile->lib_offset && copytime) {
if (nlo && copytime) {
cf_CopyFileTime(dest, src);
}
return true;