Skip to content

Commit 676abcb

Browse files
committed
15586 ddi_parse needs len
Reviewed by: Andy Fiddaman <illumos@fiddaman.net> Reviewed by: Patrick Mooney <pmooney@pfmooney.com> Approved by: Joshua M. Clulow <josh@sysmgr.org>
1 parent cf7391a commit 676abcb

File tree

7 files changed

+58
-26
lines changed

7 files changed

+58
-26
lines changed

usr/src/uts/common/io/dls/dls_mgmt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1299,7 +1299,7 @@ dls_devnet_hold_by_name(const char *link, dls_devnet_t **ddpp)
12991299
* If we reach this point it means dlmgmtd is up but has no
13001300
* mapping for the link name.
13011301
*/
1302-
if (ddi_parse(link, drv, &ppa) != DDI_SUCCESS)
1302+
if (ddi_parse_dlen(link, drv, MAXLINKNAMELEN, &ppa) != DDI_SUCCESS)
13031303
return (ENOENT);
13041304

13051305
if (IS_IPTUN_LINK(drv)) {

usr/src/uts/common/io/ib/clients/rds/rds_ioctl.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ rds_capable_interface(struct lifreq *lifrp)
8686
char ifname[LIFNAMSIZ];
8787
char drv[MAXLINKNAMELEN];
8888
uint_t ppa;
89-
char *cp;
89+
char *cp;
9090

9191
if (lifrp->lifr_type == IFT_IB)
9292
return (B_TRUE);
@@ -106,7 +106,8 @@ rds_capable_interface(struct lifreq *lifrp)
106106
return (B_TRUE);
107107
}
108108

109-
return (ddi_parse(ifname, drv, &ppa) == DDI_SUCCESS &&
109+
return (
110+
ddi_parse_dlen(ifname, drv, MAXLINKNAMELEN, &ppa) == DDI_SUCCESS &&
110111
rds_transport_ops->rds_transport_if_lookup_by_name(drv));
111112
}
112113

@@ -187,7 +188,7 @@ rds_ioctl_copyin_done(queue_t *q, mblk_t *mp)
187188
caddr_t ubuf_addr;
188189
int ubuf_size;
189190
uint_t bufsize;
190-
int i, nifs;
191+
int i, nifs;
191192
struct lifconf lifc;
192193
struct lifreq *lifrp;
193194
struct ifreq *ifrp;

usr/src/uts/common/io/ib/clients/rdsv3/rdsv3_impl.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ rdsv3_capable_interface(struct lifreq *lifrp)
104104
return (B_TRUE);
105105
}
106106

107-
return (ddi_parse(ifname, drv, &ppa) == DDI_SUCCESS &&
107+
return (
108+
ddi_parse_dlen(ifname, drv, MAXLINKNAMELEN, &ppa) == DDI_SUCCESS &&
108109
rdsv3_if_lookup_by_name(drv));
109110
}
110111

@@ -309,7 +310,8 @@ rdsv3_capable_interface_old(struct ifreq *ifrp)
309310
return (B_TRUE);
310311
}
311312

312-
return (ddi_parse(ifname, drv, &ppa) == DDI_SUCCESS &&
313+
return (
314+
ddi_parse_dlen(ifname, drv, MAXLINKNAMELEN, &ppa) == DDI_SUCCESS &&
313315
rdsv3_if_lookup_by_name(drv));
314316
}
315317

usr/src/uts/common/io/softmac/softmac_stat.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ typedef struct i_softmac_stat_info_s {
4242
* Must be the same order as mac_driver_stat.
4343
*/
4444
static i_softmac_stat_info_t i_softmac_driver_si[] = {
45-
{ MAC_STAT_IFSPEED, "ifspeed", "link_speed" },
45+
{ MAC_STAT_IFSPEED, "ifspeed", "link_speed" },
4646
{ MAC_STAT_MULTIRCV, "multircv", NULL },
47-
{ MAC_STAT_BRDCSTRCV, "brdcstrcv", NULL },
47+
{ MAC_STAT_BRDCSTRCV, "brdcstrcv", NULL },
4848
{ MAC_STAT_MULTIXMT, "multixmt", NULL },
4949
{ MAC_STAT_BRDCSTXMT, "brdcstxmt", NULL },
5050
{ MAC_STAT_NORCVBUF, "norcvbuf", "rx_no_buf" },
@@ -70,7 +70,7 @@ static i_softmac_stat_info_t i_softmac_driver_si[] = {
7070
static i_softmac_stat_info_t i_softmac_ether_si[] = {
7171
{ ETHER_STAT_ALIGN_ERRORS, "align_errors",
7272
"alignment_err" },
73-
{ ETHER_STAT_FCS_ERRORS, "fcs_errors", "crc_err" },
73+
{ ETHER_STAT_FCS_ERRORS, "fcs_errors", "crc_err" },
7474
{ ETHER_STAT_FIRST_COLLISIONS, "first_collisions", NULL },
7575
{ ETHER_STAT_MULTI_COLLISIONS, "multi_collisions", NULL },
7676
{ ETHER_STAT_SQE_ERRORS, "sqe_errors", NULL },
@@ -81,8 +81,8 @@ static i_softmac_stat_info_t i_softmac_ether_si[] = {
8181
"excessive_collisions" },
8282
{ ETHER_STAT_MACXMT_ERRORS, "macxmt_errors", NULL },
8383
{ ETHER_STAT_CARRIER_ERRORS, "carrier_errors", NULL },
84-
{ ETHER_STAT_TOOLONG_ERRORS, "toolong_errors", "length_err" },
85-
{ ETHER_STAT_MACRCV_ERRORS, "macrcv_errors",
84+
{ ETHER_STAT_TOOLONG_ERRORS, "toolong_errors", "length_err" },
85+
{ ETHER_STAT_MACRCV_ERRORS, "macrcv_errors",
8686
"Rx Error Count" },
8787

8888
{ ETHER_STAT_XCVR_ADDR, "xcvr_addr", NULL },
@@ -106,8 +106,8 @@ static i_softmac_stat_info_t i_softmac_ether_si[] = {
106106
{ ETHER_STAT_ADV_CAP_10FDX, "adv_cap_10fdx", NULL },
107107
{ ETHER_STAT_ADV_CAP_10HDX, "adv_cap_10hdx", NULL },
108108
{ ETHER_STAT_ADV_CAP_ASMPAUSE, "adv_cap_asmpause", NULL },
109-
{ ETHER_STAT_ADV_CAP_PAUSE, "adv_cap_pause", NULL },
110-
{ ETHER_STAT_ADV_CAP_AUTONEG, "adv_cap_autoneg", NULL },
109+
{ ETHER_STAT_ADV_CAP_PAUSE, "adv_cap_pause", NULL },
110+
{ ETHER_STAT_ADV_CAP_AUTONEG, "adv_cap_autoneg", NULL },
111111

112112
{ ETHER_STAT_LP_CAP_1000FDX, "lp_cap_1000fdx", NULL },
113113
{ ETHER_STAT_LP_CAP_1000HDX, "lp_cap_1000hdx", NULL },
@@ -121,7 +121,7 @@ static i_softmac_stat_info_t i_softmac_ether_si[] = {
121121

122122
{ ETHER_STAT_LINK_ASMPAUSE, "link_asmpause", NULL },
123123
{ ETHER_STAT_LINK_PAUSE, "link_pause", NULL },
124-
{ ETHER_STAT_LINK_AUTONEG, "link_autoneg", NULL },
124+
{ ETHER_STAT_LINK_AUTONEG, "link_autoneg", NULL },
125125
{ ETHER_STAT_LINK_DUPLEX, "link_duplex", "duplex" },
126126

127127
{ ETHER_STAT_TOOSHORT_ERRORS, "runt_errors", NULL },
@@ -177,8 +177,10 @@ softmac_hold_dev_kstat(softmac_t *softmac)
177177
uint_t ppa;
178178
kstat_t *ksp;
179179

180-
if (ddi_parse(softmac->smac_devname, drv, &ppa) != DDI_SUCCESS)
180+
if (ddi_parse_dlen(softmac->smac_devname, drv, MAXLINKNAMELEN, &ppa) !=
181+
DDI_SUCCESS) {
181182
return (NULL);
183+
}
182184

183185
/*
184186
* Find the kstat by the module name and the instance number.

usr/src/uts/common/os/sunddi.c

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
* Copyright (c) 1990, 2010, Oracle and/or its affiliates. All rights reserved.
2424
* Copyright 2022 Garrett D'Amore
2525
* Copyright 2022 Tintri by DDN, Inc. All rights reserved.
26+
* Copyright 2023 MNX Cloud, Inc.
2627
*/
2728

2829
#include <sys/note.h>
@@ -8957,29 +8958,54 @@ ddi_taskq_resume(ddi_taskq_t *tq)
89578958
}
89588959

89598960
int
8960-
ddi_parse(
8961-
const char *ifname,
8962-
char *alnum,
8963-
uint_t *nump)
8961+
ddi_parse(const char *ifname, char *alnum, uint_t *nump)
8962+
{
8963+
/*
8964+
* Cap "alnum" size at LIFNAMSIZ, as callers use that in most/all
8965+
* cases.
8966+
*/
8967+
return (ddi_parse_dlen(ifname, alnum, LIFNAMSIZ, nump));
8968+
}
8969+
8970+
int
8971+
ddi_parse_dlen(const char *ifname, char *alnum, size_t alnumsize, uint_t *nump)
89648972
{
89658973
const char *p;
8966-
int l;
8974+
int copy_len;
89678975
ulong_t num;
89688976
boolean_t nonum = B_TRUE;
89698977
char c;
89708978

8971-
l = strlen(ifname);
8972-
for (p = ifname + l; p != ifname; l--) {
8979+
copy_len = strlen(ifname);
8980+
for (p = ifname + copy_len; p != ifname; copy_len--) {
89738981
c = *--p;
89748982
if (!isdigit(c)) {
8975-
(void) strlcpy(alnum, ifname, l + 1);
8983+
/*
8984+
* At this point, copy_len is the length of ifname
8985+
* WITHOUT the PPA number. For "e1000g10" copy_len is 6.
8986+
*
8987+
* We must first make sure we HAVE a PPA, and we
8988+
* aren't exceeding alnumsize with copy_len and a '\0'
8989+
* terminator...
8990+
*/
8991+
int copy_len_nul = copy_len + 1;
8992+
8993+
if (nonum || alnumsize < copy_len_nul)
8994+
return (DDI_FAILURE);
8995+
8996+
/*
8997+
* ... then we abuse strlcpy() to copy over the
8998+
* driver name portion AND '\0'-terminate it.
8999+
*/
9000+
(void) strlcpy(alnum, ifname, copy_len_nul);
89769001
if (ddi_strtoul(p + 1, NULL, 10, &num) != 0)
89779002
return (DDI_FAILURE);
89789003
break;
89799004
}
89809005
nonum = B_FALSE;
89819006
}
8982-
if (l == 0 || nonum)
9007+
9008+
if (copy_len == 0)
89839009
return (DDI_FAILURE);
89849010

89859011
*nump = num;

usr/src/uts/common/sys/sunddi.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2233,6 +2233,8 @@ boolean_t ddi_taskq_suspended(ddi_taskq_t *tq);
22332233
* <numeric> is maximal.
22342234
*/
22352235
int ddi_parse(const char *, char *, uint_t *);
2236+
/* Version with caller-specified destination buffer length. */
2237+
int ddi_parse_dlen(const char *, char *, size_t, uint_t *);
22362238

22372239
/*
22382240
* DDI interrupt priority level

usr/src/uts/sun4v/io/vsw.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2166,8 +2166,7 @@ vsw_update_md_prop(vsw_t *vswp, md_t *mdp, mde_cookie_t node)
21662166
* the vsw is being changed to 'routed' mode.
21672167
*/
21682168
if ((strlen(physname) != 0) &&
2169-
(ddi_parse(physname, drv,
2170-
&ddi_instance) != DDI_SUCCESS)) {
2169+
(ddi_parse(physname, drv, &ddi_instance) != DDI_SUCCESS)) {
21712170
cmn_err(CE_WARN, "!vsw%d: physical device %s is not"
21722171
" a valid device name/instance",
21732172
vswp->instance, physname);

0 commit comments

Comments
 (0)