Skip to content

Commit

Permalink
tsnep: Fix tsnep_request_irq() format-overflow warning
Browse files Browse the repository at this point in the history
[ Upstream commit 00e984c ]

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.

Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202310182028.vmDthIUa-lkp@intel.com/
Signed-off-by: Gerhard Engleder <gerhard@engleder-embedded.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
Link: https://lore.kernel.org/r/20231023183856.58373-1-gerhard@engleder-embedded.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Gerhard Engleder authored and gregkh committed Nov 28, 2023
1 parent 6a2c311 commit 6165ae1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion drivers/net/ethernet/engleder/tsnep.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,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;
Expand Down
12 changes: 6 additions & 6 deletions drivers/net/ethernet/engleder/tsnep_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1778,14 +1778,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;
}
Expand Down

0 comments on commit 6165ae1

Please sign in to comment.