From 4c0891d06364417d026963db847d7e401e1d53b6 Mon Sep 17 00:00:00 2001 From: Oskar Wirga <10386631+oskarwirga@users.noreply.github.com> Date: Mon, 2 May 2022 11:25:10 -0400 Subject: [PATCH] Update stream.c Context: CFI indirect function call sanitization checks that function signatures at runtime match those that were determined at compile time. This fix ensures that fclose has the correct function signature when being passed a stream. --- src/stream.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/stream.c b/src/stream.c index 6559e1d..fbc39b9 100644 --- a/src/stream.c +++ b/src/stream.c @@ -118,11 +118,17 @@ static opus_int64 op_ftell(void *_stream){ #endif } +static int op_fclose(void *_stream){ + /*This indirection maintains fclose's type signature which is necessary for + Control Flow Integrity.*/ + return fclose((FILE *)_stream); +} + static const OpusFileCallbacks OP_FILE_CALLBACKS={ op_fread, op_fseek, op_ftell, - (op_close_func)fclose + op_fclose }; #if defined(_WIN32) @@ -257,7 +263,7 @@ static const OpusFileCallbacks OP_UNSEEKABLE_FILE_CALLBACKS={ op_fread, op_fseek_fail, op_ftell, - (op_close_func)fclose + op_fclose }; # define WIN32_LEAN_AND_MEAN