Skip to content

Commit b382c86

Browse files
committed
drivers/blazer_usb.c, drivers/nutdrv_qx.c: play safer with temporary buffers, pre-zero some [#3529]
Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
1 parent e308c36 commit b382c86

3 files changed

Lines changed: 12 additions & 2 deletions

File tree

NEWS.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ https://github.com/networkupstools/nut/milestone/13
134134
* Drivers with libusb-1.0 code path, and `nutdrv_qx` in particular: revise
135135
to fix per-close `libusb_exit()` deadlock, and escalate a persistent
136136
`LIBUSB_ERROR_OVERFLOW` state to USB reset handling. [PR #3448]
137+
* Some driver code paths used buffers sent via USB transfers as fixed-size
138+
chunks populated only partially with bytes we intended. These buffers are
139+
now more diligently pre-zeroed as their siblings were in other code paths,
140+
to avoid sending host stack garbage to a device. [#3529]
137141

138142
- NUT client libraries:
139143
* Complete support for actions documented in `docs/net-protocol.txt`

drivers/blazer_usb.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
#endif /* WIN32 */
3838

3939
#define DRIVER_NAME "Megatec/Q1 protocol USB driver"
40-
#define DRIVER_VERSION "0.24"
40+
#define DRIVER_VERSION "0.25"
4141

4242
/* driver description structure */
4343
upsdrv_info_t upsdrv_info = {
@@ -234,6 +234,7 @@ static int ippon_command(const char *cmd, char *buf, size_t buflen)
234234
int ret, len;
235235
size_t i;
236236

237+
memset(tmp, 0, sizeof(tmp));
237238
snprintf(tmp, sizeof(tmp), "%s", cmd);
238239

239240
for (i = 0; i < strlen(tmp); i += (size_t)ret) {

drivers/nutdrv_qx.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
# define DRIVER_NAME "Generic Q* Serial driver"
5959
#endif /* QX_USB */
6060

61-
#define DRIVER_VERSION "0.51"
61+
#define DRIVER_VERSION "0.52"
6262

6363
#ifdef QX_SERIAL
6464
# include "serial.h"
@@ -923,6 +923,8 @@ static int phoenix_command(const char *cmd, size_t cmdlen, char *buf, size_t buf
923923
for (i = 0; i < 8; i++) {
924924

925925
/* Read data in 8-byte chunks */
926+
memset(tmp, 0, sizeof(tmp));
927+
926928
/* ret = usb->get_interrupt(udev, (unsigned char *)tmp, 8, 1000); */
927929
ret = usb_interrupt_read(udev,
928930
0x81,
@@ -1640,6 +1642,7 @@ static int fuji_command(const char *cmd, size_t cmdlen, char *buf, size_t buflen
16401642
/* Send command */
16411643

16421644
/* Remove the CR */
1645+
memset(command, 0, sizeof(command));
16431646
snprintf(command, sizeof(command), "%.*s", (int)strcspn(cmd, "\r"), cmd);
16441647

16451648
/* Length of the command that will be sent to the UPS can be
@@ -1947,6 +1950,8 @@ static int ablerex_command(const char *cmd, size_t cmdlen, char *buf, size_t buf
19471950
int ret;
19481951

19491952
memset(buf, 0, buflen);
1953+
memset(tmp, 0, sizeof(tmp));
1954+
19501955
tmp[0] = 0x05;
19511956
tmp[1] = 0;
19521957
tmp[2] = 1 + (char)strcspn(cmd, "\r");

0 commit comments

Comments
 (0)