mirror of
https://github.com/rstrouse/ESPSomfy-RTS.git
synced 2026-10-31 13:52:15 +01:00
fix: compare the coredump build SHA without reading past the array
app_elf_sha256 has no terminator (IDF 4.4 fills all 17 bytes), so strcmp never matched the running build and %s printed whatever followed it. Copy it into a terminated buffer first. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
2ee7af51ab
commit
e1c76bc2af
2 changed files with 15 additions and 1 deletions
|
|
@ -86,7 +86,11 @@ void setup() {
|
|||
#endif
|
||||
// The backtrace only decodes against the firmware.elf of the build that
|
||||
// crashed, so say whether that is the one running now.
|
||||
const char *crashedSha = (const char *)summary.app_elf_sha256;
|
||||
// app_elf_sha256 isn't always terminated, so copy it before comparing or
|
||||
// printing it.
|
||||
char crashedSha[APP_ELF_SHA256_SZ];
|
||||
static_assert(sizeof(crashedSha) <= sizeof(summary.app_elf_sha256), "copy would read past app_elf_sha256");
|
||||
SETCHARPROP(crashedSha, (const char *)summary.app_elf_sha256, sizeof(crashedSha));
|
||||
char runningSha[APP_ELF_SHA256_SZ] = {0};
|
||||
getRunningElfSha(runningSha, sizeof(runningSha));
|
||||
if(strcmp(crashedSha, runningSha) == 0)
|
||||
|
|
|
|||
|
|
@ -79,6 +79,15 @@ static void test_setcharprop_truncates_long_value() {
|
|||
SETCHARPROP(prop, "abcdefgh", sizeof(prop));
|
||||
TEST_ASSERT_EQUAL_STRING("abcd", prop);
|
||||
}
|
||||
static void test_setcharprop_unterminated_source() {
|
||||
// A coredump's app_elf_sha256 can be full of hex digits with no terminator.
|
||||
// The copy must stop inside the array and come out as a comparable string.
|
||||
const char crashed[17] = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','9'};
|
||||
char sha[sizeof(crashed)];
|
||||
SETCHARPROP(sha, crashed, sizeof(sha));
|
||||
TEST_ASSERT_EQUAL_STRING("0123456789abcdef", sha);
|
||||
TEST_ASSERT_EQUAL_INT(0, strcmp(sha, "0123456789abcdef"));
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* sortArray / sortArrayReverse
|
||||
|
|
@ -202,6 +211,7 @@ int main(int argc, char **argv) {
|
|||
RUN_TEST(test_toBoolean_unknown_uses_default);
|
||||
RUN_TEST(test_setcharprop_copies_short_value);
|
||||
RUN_TEST(test_setcharprop_truncates_long_value);
|
||||
RUN_TEST(test_setcharprop_unterminated_source);
|
||||
RUN_TEST(test_sortArray_ascending);
|
||||
RUN_TEST(test_sortArrayReverse_descending);
|
||||
RUN_TEST(test_sortArray_custom_comparator);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue