From 3a717246b0f887b9128d1a1736d982c559a56dfe Mon Sep 17 00:00:00 2001 From: Patrik Andersson Date: Tue, 6 Aug 2024 12:23:10 +0200 Subject: [PATCH 1/2] fix(sd): Fix use after free --- libraries/SD/src/sd_diskio.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libraries/SD/src/sd_diskio.cpp b/libraries/SD/src/sd_diskio.cpp index 497e27d326c..ae4fcf24863 100644 --- a/libraries/SD/src/sd_diskio.cpp +++ b/libraries/SD/src/sd_diskio.cpp @@ -671,8 +671,10 @@ uint8_t sdcard_uninit(uint8_t pdrv) { if (pdrv >= FF_VOLUMES || card == NULL) { return 1; } - AcquireSPI lock(card); - sdTransaction(pdrv, GO_IDLE_STATE, 0, NULL); + { + AcquireSPI lock(card); + sdTransaction(pdrv, GO_IDLE_STATE, 0, NULL); + } // lock is destructed here ff_diskio_register(pdrv, NULL); s_cards[pdrv] = NULL; esp_err_t err = ESP_OK; From 60e9415bf3f068966a011b7fd0cf6f81604bf8f9 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci-lite[bot]" <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Date: Wed, 7 Aug 2024 14:32:07 +0000 Subject: [PATCH 2/2] ci(pre-commit): Apply automatic fixes --- libraries/SD/src/sd_diskio.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/SD/src/sd_diskio.cpp b/libraries/SD/src/sd_diskio.cpp index ae4fcf24863..40d6ede9f81 100644 --- a/libraries/SD/src/sd_diskio.cpp +++ b/libraries/SD/src/sd_diskio.cpp @@ -674,7 +674,7 @@ uint8_t sdcard_uninit(uint8_t pdrv) { { AcquireSPI lock(card); sdTransaction(pdrv, GO_IDLE_STATE, 0, NULL); - } // lock is destructed here + } // lock is destructed here ff_diskio_register(pdrv, NULL); s_cards[pdrv] = NULL; esp_err_t err = ESP_OK;