From d25f06d98e819a566e360dae334cf374129618fd Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Mon, 9 Nov 2026 23:11:57 +0700 Subject: [PATCH 1/2] save_buffer8: don't read past the source on a partial last word The 4-byte packing loop read up to 3 bytes beyond src when length was not a multiple of 4 (ASan heap-buffer-overflow in data test_ss8). Pack byte by byte into the zeroed backing buffer instead. Co-Authored-By: Claude Opus 5.5 --- client/src/graph.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/client/src/graph.c b/client/src/graph.c index 0bb403942..6223306d1 100644 --- a/client/src/graph.c +++ b/client/src/graph.c @@ -582,12 +582,9 @@ buffer_savestate_t save_buffer8(uint8_t *src, size_t length) { buffer_savestate_t bst = {0}; return bst; } - size_t index = 0; - - // Pack the source array into the backing array - for (size_t i = 0; i < length; i += 4) { - savedBuffer[index] = MemLeToUint4byte(src + i); - index++; + // Pack the source array into the backing array, little endian, last word zero padded + for (size_t i = 0; i < length; i++) { + savedBuffer[i / 4] |= (uint32_t)src[i] << ((i % 4) * 8); } buffer_savestate_t bst = { From e23ba0ec99dbb8f471c63361c1630672025c6372 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Mon, 9 Nov 2026 23:11:57 +0700 Subject: [PATCH 2/2] hf piv: print unsigned long length with %lu, not PRIu64 v is unsigned long; PRIu64 is "llu" on macOS, so clang fails the build with the PrintAndLogEx format attribute. Co-Authored-By: Claude Opus 5.5 --- client/src/cmdpiv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/cmdpiv.c b/client/src/cmdpiv.c index 165f77c1f..d6f66bd9e 100644 --- a/client/src/cmdpiv.c +++ b/client/src/cmdpiv.c @@ -392,7 +392,7 @@ static void piv_tag_dump_int_array(const struct tlv *tlv, const struct piv_tag * for (int i = 0; i < sub_tlv.len; i++) { v = (v << 8) + sub_tlv.value[i]; } - PrintAndLogEx(NORMAL, _YELLOW_("%" PRIu64) " bytes (" _YELLOW_("%" PRIx64) ")", v, v); + PrintAndLogEx(NORMAL, _YELLOW_("%lu") " bytes (" _YELLOW_("%lx") ")", v, v); } else { // Number is to big. Just print hex value PrintAndLogEx(NORMAL, _YELLOW_("0x%s"), sprint_hex_inrow(sub_tlv.value, sub_tlv.len));