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.
This commit is contained in:
Pieter du Preez 2020-04-19 22:05:44 +00:00 committed by UweBonnes
parent 164eb43f00
commit d55cea871d
1 changed files with 4 additions and 1 deletions

View File

@ -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++);