util/error: Fix use-after-free errors reported by Coverity
PATCH 1/1 util/error: Fix use-after-free errors reported by Coverity
Fix use-after-free errors in the code path that called error_handle(). A call to error_handle() will now either free the passed Error 'err' or assign it to '*errp' if '*errp' is currently NULL. This ensures that 'err' either has been freed or is assigned to '*errp' if this function returns. Adjust the two callers of this function to not assign the 'err' to '*errp' themselves, since this is now handled by error_handle().
--- util/error.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
util/error.c +4 -6
@@ -46,6 +46,10 @@ static void error_handle(Error **errp, Error *err) }if (errp == &error_warn) {warn_report_err (err); + }else if (errp && !*errp) { + *errp = err; + }else { +error_free (err); } }
@@ -76,7 +80,6 @@ static void error_setv(Error **errp, err->func = func;error_handle (errp, err); - *errp = err; errno = saved_errno; }
@@ -289,11 +292,6 @@ void error_propagate(Error **dst_errp, Error *local_err)return ; }error_handle (dst_errp, local_err); -if (dst_errp && !*dst_errp) { - *dst_errp = local_err; - }else { -error_free (local_err); - } } void error_propagate_prepend(Error **dst_errp, Error *err,
Signature · 1 line
2.39.1
Quoted 10 lines · Stefan Berger
Fix use-after-free errors in the code path that called
error_handle(). A call toerror_handle()will now either free the passed Error 'err' or assign it to '*errp' if '*errp' is currently NULL. This ensures that 'err' either has been freed or is assigned to '*errp' if this function returns. Adjust the two callers of this function to not assign the 'err' to '*errp' themselves, since this is now handled byerror_handle().Signed-off-by Stefan Berger <[email protected]>---
Do we think this needs to be fixed for 8.0 ?
thanks
-- PMM
Quoted 11 lines · Stefan Berger
Fix use-after-free errors in the code path that called
error_handle(). A call toerror_handle()will now either free the passed Error 'err' or assign it to '*errp' if '*errp' is currently NULL. This ensures that 'err' either has been freed or is assigned to '*errp' if this function returns. Adjust the two callers of this function to not assign the 'err' to '*errp' themselves, since this is now handled byerror_handle().Signed-off-by Stefan Berger <[email protected]>--- util/error.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
Hi
Quoted 8 lines · Stefan Berger
Fix use-after-free errors in the code path that called
error_handle(). A call toerror_handle()will now either free the passed Error 'err' or assign it to '*errp' if '*errp' is currently NULL. This ensures that 'err' either has been freed or is assigned to '*errp' if this function returns. Adjust the two callers of this function to not assign the 'err' to '*errp' themselves, since this is now handled byerror_handle().
worth including for 8.0 imho.
Quoted 43 lines
Signed-off-by Stefan Berger <[email protected]>--- util/error.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)util/error.c +4
-7@@ -46,6 +46,10 @@ static void error_handle(Error **errp, Error *err) }if (errp == &error_warn) {warn_report_err (err); + }else if (errp && !*errp) { + *errp = err; + }else { +error_free (err); } }@@ -76,7 +80,6 @@ static void error_setv(Error **errp, err->func = func;error_handle (errp, err); - *errp = err; errno = saved_errno; }@@ -289,11 +292,6 @@ void error_propagate(Error **dst_errp, Error *local_err)return ; }error_handle (dst_errp, local_err); -if (dst_errp && !*dst_errp) { - *dst_errp = local_err; - }else { -error_free (local_err); - } } void error_propagate_prepend(Error **dst_errp, Error *err, --2.39.1
Signature · 1 line
Marc-André Lureau