From 3bbd1a1a005698fcf1aaeae0065a8f2f97fdf4be Mon Sep 17 00:00:00 2001 From: Eric van Gyzen Date: Wed, 29 Mar 2023 14:14:40 -0500 Subject: [PATCH] camcontrol powermode: fix use-after-free Free the ccb after processing the response therein. Reported by: Coverity Fixes: 3bed0179ee571ba3ceadb2773f86d57af8bc5499 MFC after: 1 week Sponsored by: Dell EMC Isilon --- sbin/camcontrol/camcontrol.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/sbin/camcontrol/camcontrol.c b/sbin/camcontrol/camcontrol.c index 489c3026537..9e50fbf2646 100644 --- a/sbin/camcontrol/camcontrol.c +++ b/sbin/camcontrol/camcontrol.c @@ -9312,12 +9312,11 @@ atapm(struct cam_device *device, int argc, char **argv, /*timeout*/timeout ? timeout : 30 * 1000, /*force48bit*/0); + if (retval == 0 && cmd == ATA_CHECK_POWER_MODE) + retval = atapm_proc_resp(device, ccb); + cam_freeccb(ccb); - - if (retval || cmd != ATA_CHECK_POWER_MODE) - return (retval); - - return (atapm_proc_resp(device, ccb)); + return (retval); } static int