From d55cea871dc3dc9f56bdaa631da0e643a04c4949 Mon Sep 17 00:00:00 2001 From: Pieter du Preez Date: Sun, 19 Apr 2020 22:05:44 +0000 Subject: [PATCH] Fixed overrun and formatting, when dumping data in swolisten. The swolisten program failed to print the cbw buffer correctly while in dump mode. As printf() is used to print the dump, it is expected that the cbw buffer is zero-terminated, which would only be the case, if the cbw buffer is initialized with zeros, before filling it with new data. One could set the entire cbw buffer to zero, but it will be more efficient to only set the size-th byte to zero. Furthermore, if a '%' character appears in the data, printf() will attempt to format it, causing unexpected results. This patch fixes the above 2 problems, by: 1. using the size variable to set the size-th byte of the cbw buffer to zero, before passing it to printf(). 2. calling printf() with a "%s" formatting string, followed by the data buffer, cbw. --- scripts/swolisten.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/swolisten.c b/scripts/swolisten.c index 1ce141aa..f7408fd7 100644 --- a/scripts/swolisten.c +++ b/scripts/swolisten.c @@ -442,7 +442,10 @@ int usbFeeder(void) { unsigned char *c=cbw; if (options.dump) - printf(cbw); + { + cbw[size] = 0; + printf("%s", (char*)cbw); + } else while (size--) _protocolPump(c++);