Skip to content

Commit

Permalink
hosted/jlink: Avoid stripping the copyright string located after a nu…
Browse files Browse the repository at this point in the history
…l byte

* According to Wireshark usbmon dumps, the firmware returns 112 bytes of version,
  including some copyright information after an effectively 0-terminator.
* Use strchr() instead of index() for Windows reasons.
* Make sure the version buffer contains at least one NULL
* And avoid replacing the only NULL with LF, losing null-termination in the process
  • Loading branch information
ALTracer authored and dragonmux committed Nov 11, 2023
1 parent 3cc5598 commit dc84ef0
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/platforms/hosted/jlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,16 @@ static bool jlink_get_version(void)
if (version_length > sizeof(jlink.fw_version))
return false;

/* Read vesion string directly into jlink.version */
/* Read version string directly into jlink.version */
bmda_usb_transfer(bmda_probe_info.usb_link, NULL, 0, jlink.fw_version, version_length, JLINK_USB_TIMEOUT);
jlink.fw_version[version_length - 1U] = '\0'; /* Ensure null termination */
/* Ensure null termination */
char *const null_termination = jlink.fw_version + version_length - 1U;
*null_termination = '\0';

/* Replace NULL separating version and copyright string, if it exists */
char *const null_separator = strchr(jlink.fw_version, '\0');
if (null_separator != NULL && null_separator != null_termination)
*null_separator = '\n';

DEBUG_INFO("Firmware version: %s\n", jlink.fw_version);

Expand Down

0 comments on commit dc84ef0

Please sign in to comment.