]> git.sur5r.net Git - openocd/commitdiff
target/cortex_m: avoid dwt comparator overflow
authorCody P Schafer <openocd@codyps.com>
Wed, 7 Mar 2018 16:31:35 +0000 (11:31 -0500)
committerTomas Vanek <vanekt@fbl.cz>
Wed, 4 Apr 2018 20:24:53 +0000 (21:24 +0100)
Avoid ever overflowing the DWT_COMPARATOR array by allocating space for
16 comparators (the field is masked by 0xf).

On a stm32f767zi chip (on a nucleo-767zi board) I've been seeing crashes
with address sanitizer enabled due to its (apparent) 10 present
comparators. This appears to be due to
https://sourceforge.net/p/openocd/tickets/178/.

In non-address sanitizer builds, this would likely cause some random
memory to be written to in some cases. (see above bug for observations).

Change-Id: I2b7d599eb326236dbc93f74b350c442c9a502c4b
Signed-off-by: Cody P Schafer <openocd@codyps.com>
Reviewed-on: http://openocd.zylin.com/4458
Tested-by: jenkins
Reviewed-by: Christopher Head <chead@zaber.com>
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
src/target/cortex_m.c

index 14ebba318b28d50f568aaa183c07ebd29c1f5511..a356350a2837f218435650e32b005d1fedf3f965 100644 (file)
@@ -1854,6 +1854,18 @@ static struct dwt_reg dwt_comp[] = {
        DWT_COMPARATOR(1),
        DWT_COMPARATOR(2),
        DWT_COMPARATOR(3),
+       DWT_COMPARATOR(4),
+       DWT_COMPARATOR(5),
+       DWT_COMPARATOR(6),
+       DWT_COMPARATOR(7),
+       DWT_COMPARATOR(8),
+       DWT_COMPARATOR(9),
+       DWT_COMPARATOR(10),
+       DWT_COMPARATOR(11),
+       DWT_COMPARATOR(12),
+       DWT_COMPARATOR(13),
+       DWT_COMPARATOR(14),
+       DWT_COMPARATOR(15),
 #undef DWT_COMPARATOR
 };
 
@@ -1887,6 +1899,7 @@ void cortex_m_dwt_setup(struct cortex_m_common *cm, struct target *target)
        int reg, i;
 
        target_read_u32(target, DWT_CTRL, &dwtcr);
+       LOG_DEBUG("DWT_CTRL: 0x%" PRIx32, dwtcr);
        if (!dwtcr) {
                LOG_DEBUG("no DWT");
                return;