diff --git a/client/comms.c b/client/comms.c index 350af3d55..5aa704728 100644 --- a/client/comms.c +++ b/client/comms.c @@ -119,10 +119,6 @@ static void SendCommandNG_internal(uint16_t cmd, uint8_t *data, size_t len, bool PrintAndLogEx(WARNING, "Sending %d bytes of payload is too much, abort", len); return; } - if (data == NULL) { - PrintAndLogEx(WARNING, "SendCommandNG_internal NULL pointer, abort"); - return; - } PacketCommandNGPostamble *tx_post = (PacketCommandNGPostamble *)((uint8_t *)&txBufferNG + sizeof(PacketCommandNGPreamble) + len); @@ -140,7 +136,8 @@ static void SendCommandNG_internal(uint16_t cmd, uint8_t *data, size_t len, bool txBufferNG.pre.ng = ng; txBufferNG.pre.length = len; txBufferNG.pre.cmd = cmd; - memcpy(&txBufferNG.data, data, len); + if ( len > 0 && data ) + memcpy(&txBufferNG.data, data, len); if ((conn.send_via_fpc_usart && conn.send_with_crc_on_fpc) || ((!conn.send_via_fpc_usart) && conn.send_with_crc_on_usb)) { uint8_t first, second; diff --git a/client/util.c b/client/util.c index 254c369ec..568a022f1 100644 --- a/client/util.c +++ b/client/util.c @@ -170,6 +170,8 @@ bool CheckStringIsHEXValue(const char *value) { void hex_to_buffer(const uint8_t *buf, const uint8_t *hex_data, const size_t hex_len, const size_t hex_max_len, const size_t min_str_len, const size_t spaces_between, bool uppercase) { + if (buf == NULL ) return; + char *tmp = (char *)buf; size_t i; memset(tmp, 0x00, hex_max_len); @@ -195,12 +197,16 @@ void hex_to_buffer(const uint8_t *buf, const uint8_t *hex_data, const size_t hex // printing and converting functions void print_hex(const uint8_t *data, const size_t len) { + if (data == NULL || len == 0 ) return; + for (size_t i = 0; i < len; i++) printf("%02x ", data[i]); printf("\n"); } void print_hex_break(const uint8_t *data, const size_t len, uint8_t breaks) { + if (data == NULL || len == 0 ) return; + int rownum = 0; printf("[%02d] | ", rownum); for (size_t i = 0; i < len; ++i) {