covert_byte_to_hex() converts each input byte into two hexadecimal
characters and writes them into the output buffer.

The function currently uses sprintf() for every byte. Although the caller
allocates a large enough buffer for the dumped switch data, using
sprintf() triggers diagnostics. Use snprintf() with a size of 3 for the
two hexadecimal characters and the terminating null byte.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes: 0d8d7bd720ba ("net/ice: support DDP dump switch rule binary")
Cc: [email protected]

Signed-off-by: Artem Novikov <[email protected]>
---
 drivers/net/intel/ice/ice_diagnose.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/intel/ice/ice_diagnose.c 
b/drivers/net/intel/ice/ice_diagnose.c
index 4946ace7ae..8c41b44e3f 100644
--- a/drivers/net/intel/ice/ice_diagnose.c
+++ b/drivers/net/intel/ice/ice_diagnose.c
@@ -430,7 +430,7 @@ covert_byte_to_hex(uint8_t **outbuf, const uint8_t *inbuf, 
uint32_t inbuf_size)
        uint32_t i;
        uint8_t *buffer = *outbuf;
        for (i = 0; i < inbuf_size; ++i)
-               sprintf((char *)(buffer + i * 2), "%02X", inbuf[i]);
+               snprintf((char *)(buffer + i * 2), 3, "%02X", inbuf[i]);
 
        return inbuf_size * 2;
 }

Reply via email to