tsnep: Fix tsnep_request_irq() format-overflow warning
Subsystems (2)
PATCH 1/1 tsnep: Fix tsnep_request_irq() format-overflow warning
Compiler warns about a possible format-overflow in tsnep_request_irq():drivers/net/ethernet/engleder/tsnep_main.c:884:55: warning: 'sprintf' may write a terminating nul past the end of the destination [-Wformat-overflow=]
sprintf(queue->name, "%s-rx-%d", name,
^
drivers/net/ethernet/engleder/tsnep_main.c:881:55: warning: 'sprintf' may write a terminating nul past the end of the destination [-Wformat-overflow=]
sprintf(queue->name, "%s-tx-%d", name,
^
drivers/net/ethernet/engleder/tsnep_main.c:878:49: warning: '-txrx-' directive writing 6 bytes into a region of size between 5 and 25 [-Wformat-overflow=]
sprintf(queue->name, "%s-txrx-%d", name,
^~~~~~Actually overflow cannot happen. Name is limited to IFNAMSIZ, because netdev_name() is called during ndo_open(). queue_index is single char, because less than 10 queues are supported.
Fix warning with snprintf(). Additionally increase buffer to 32 bytes, because those 7 additional bytes were unused anyway.
--- drivers/net/ethernet/engleder/tsnep.h | 2 +- drivers/net/ethernet/engleder/tsnep_main.c | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-)
drivers/net/ethernet/engleder/tsnep.h +1 -1
@@ -143,7 +143,7 @@ struct tsnep_rx {struct tsnep_queue {struct tsnep_adapter *adapter; -char name[IFNAMSIZ +9 ]; +char name[IFNAMSIZ +16 ];struct tsnep_tx *tx;struct tsnep_rx *rx;
drivers/net/ethernet/engleder/tsnep_main.c +6 -6
@@ -1830,14 +1830,14 @@ static int tsnep_request_irq(struct tsnep_queue *queue, bool first) dev = queue->adapter; }else {if (queue->tx && queue->rx) -sprintf (queue->name,"%s-txrx-%d" , name, - queue->rx->queue_index); +snprintf (queue->name,sizeof (queue->name),"%s-txrx-%d" , + name, queue->rx->queue_index);else if (queue->tx) -sprintf (queue->name,"%s-tx-%d" , name, - queue->tx->queue_index); +snprintf (queue->name,sizeof (queue->name),"%s-tx-%d" , + name, queue->tx->queue_index);else -sprintf (queue->name,"%s-rx-%d" , name, - queue->rx->queue_index); +snprintf (queue->name,sizeof (queue->name),"%s-rx-%d" , + name, queue->rx->queue_index); handler = tsnep_irq_txrx; dev = queue; }
Signature · 1 line
2.39.2
Quoted 11 lines · Gerhard Engleder
Compiler warns about a possible format-overflow in
tsnep_request_irq():drivers/net/ethernet/engleder/tsnep_main.c:884:55: warning: 'sprintf' may write a terminating nul past the end of the destination [-Wformat-overflow=]sprintf(queue->name, "%s-rx-%d", name, ^ drivers/net/ethernet/engleder/tsnep_main.c:881:55: warning: 'sprintf' may write a terminating nul past the end of the destination [-Wformat-overflow=] sprintf(queue->name, "%s-tx-%d", name, ^ drivers/net/ethernet/engleder/tsnep_main.c:878:49: warning: '-txrx-' directive writing 6 bytes into a region of size between 5 and 25 [-Wformat-overflow=] sprintf(queue->name, "%s-txrx-%d", name, ^~~~~~
Quoted 7 lines
Actually overflow cannot happen. Name is limited to IFNAMSIZ, because
netdev_name()is called duringndo_open().queue_indexis single char, because less than 10 queues are supported.Fix warning with
snprintf(). Additionally increase buffer to 32 bytes, because those 7 additional bytes were unused anyway.
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 11 lines · On Mon, 23 Oct 2023 20:38:56 +0200 you wrote:
Compiler warns about a possible format-overflow in
tsnep_request_irq():drivers/net/ethernet/engleder/tsnep_main.c:884:55: warning: 'sprintf' may write a terminating nul past the end of the destination [-Wformat-overflow=]sprintf(queue->name, "%s-rx-%d", name, ^ drivers/net/ethernet/engleder/tsnep_main.c:881:55: warning: 'sprintf' may write a terminating nul past the end of the destination [-Wformat-overflow=] sprintf(queue->name, "%s-tx-%d", name, ^ drivers/net/ethernet/engleder/tsnep_main.c:878:49: warning: '-txrx-' directive writing 6 bytes into a region of size between 5 and 25 [-Wformat-overflow=] sprintf(queue->name, "%s-txrx-%d", name, ^~~~~~
Quoted 1 line
[...]
Here is the summary with links:
- [net-next] tsnep: Fix tsnep_request_irq() format-overflow warning
https://git.kernel.org/netdev/net-next/c/00e984cb986b
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html