From 1c32fc05b672d318578efda59371d4a426185c51 Mon Sep 17 00:00:00 2001 From: Jerry Jacobs Date: Thu, 7 Apr 2016 12:08:05 +0200 Subject: [PATCH] st-probe: Fix segfault when programmer is already busy and null pointers are in the list --- src/st-probe.c | 3 +++ src/stlink-common.c | 2 ++ src/stlink-usb.c | 3 +++ 3 files changed, 8 insertions(+) diff --git a/src/st-probe.c b/src/st-probe.c index f5cf3d829..b58bb7ad6 100644 --- a/src/st-probe.c +++ b/src/st-probe.c @@ -8,6 +8,9 @@ void stlink_print_info(stlink_t *sl) { const chip_params_t *params = NULL; + if (!sl) + return; + for (size_t n = 0; n < sizeof(sl->serial); n++) printf("%02x", sl->serial[n]); printf("\n"); diff --git a/src/stlink-common.c b/src/stlink-common.c index 3a6e260d1..18c76fb86 100644 --- a/src/stlink-common.c +++ b/src/stlink-common.c @@ -481,6 +481,8 @@ static inline void write_flash_cr_bker_pnb(stlink_t *sl, uint32_t n) { void stlink_close(stlink_t *sl) { DLOG("*** stlink_close ***\n"); + if (!sl) + return; sl->backend->close(sl); free(sl); } diff --git a/src/stlink-usb.c b/src/stlink-usb.c index ab555785c..8fed467ba 100644 --- a/src/stlink-usb.c +++ b/src/stlink-usb.c @@ -15,6 +15,9 @@ enum SCSI_Generic_Direction {SG_DXFER_TO_DEV=0, SG_DXFER_FROM_DEV=0x80}; void _stlink_usb_close(stlink_t* sl) { + if (!sl) + return; + struct stlink_libusb * const handle = sl->backend_data; // maybe we couldn't even get the usb device? if (handle != NULL) {