st-probe: Fix segfault when programmer is already busy and null pointers are in the...
authorJerry Jacobs <jerry.jacobs@dualinventive.com>
Thu, 7 Apr 2016 10:08:05 +0000 (12:08 +0200)
committerJerry Jacobs <jerry.jacobs@dualinventive.com>
Thu, 7 Apr 2016 10:08:05 +0000 (12:08 +0200)
src/st-probe.c
src/stlink-common.c
src/stlink-usb.c

index f5cf3d8291c5e63a0af7dd006c1594cd2115ce4b..b58bb7ad6cbe3fd9695d3d287e75141627809663 100644 (file)
@@ -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");
index 3a6e260d1706c194641e36daf4516d671d75037f..18c76fb86c109b242d32c7f8080a88d67941ca60 100644 (file)
@@ -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);
 }
index ab555785c27ac4b1cf68afacfae9fabe3e6073b3..8fed467ba7432c55aca960287fbacf5fcb80a675 100644 (file)
@@ -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) {