Skip to content

Commit 492adcf

Browse files
Vasundhara Volamdavem330
authored andcommitted
bnxt_en: Use memcpy to copy VPD field info.
Using strlcpy() to copy from VPD is not correct because VPD strings are not necessarily NULL terminated. Use memcpy() to copy the VPD length up to the destination buffer size - 1. The destination is zeroed memory so it will always be NULL terminated. Fixes: a0d0fd7 ("bnxt_en: Read partno and serialno of the board from VPD") Signed-off-by: Vasundhara Volam <vasundhara-v.volam@broadcom.com> Signed-off-by: Michael Chan <michael.chan@broadcom.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent fe81d9f commit 492adcf

File tree

1 file changed

+5
-3
lines changed
  • drivers/net/ethernet/broadcom/bnxt

1 file changed

+5
-3
lines changed

drivers/net/ethernet/broadcom/bnxt/bnxt.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12090,7 +12090,7 @@ static int bnxt_init_mac_addr(struct bnxt *bp)
1209012090
static void bnxt_vpd_read_info(struct bnxt *bp)
1209112091
{
1209212092
struct pci_dev *pdev = bp->pdev;
12093-
int i, len, pos, ro_size;
12093+
int i, len, pos, ro_size, size;
1209412094
ssize_t vpd_size;
1209512095
u8 *vpd_data;
1209612096

@@ -12125,7 +12125,8 @@ static void bnxt_vpd_read_info(struct bnxt *bp)
1212512125
if (len + pos > vpd_size)
1212612126
goto read_sn;
1212712127

12128-
strlcpy(bp->board_partno, &vpd_data[pos], min(len, BNXT_VPD_FLD_LEN));
12128+
size = min(len, BNXT_VPD_FLD_LEN - 1);
12129+
memcpy(bp->board_partno, &vpd_data[pos], size);
1212912130

1213012131
read_sn:
1213112132
pos = pci_vpd_find_info_keyword(vpd_data, i, ro_size,
@@ -12138,7 +12139,8 @@ static void bnxt_vpd_read_info(struct bnxt *bp)
1213812139
if (len + pos > vpd_size)
1213912140
goto exit;
1214012141

12141-
strlcpy(bp->board_serialno, &vpd_data[pos], min(len, BNXT_VPD_FLD_LEN));
12142+
size = min(len, BNXT_VPD_FLD_LEN - 1);
12143+
memcpy(bp->board_serialno, &vpd_data[pos], size);
1214212144
exit:
1214312145
kfree(vpd_data);
1214412146
}

0 commit comments

Comments
 (0)