net/smc/smc_pnet.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
strncpy is deprecated for use on NUL-terminated strings, as indicated in
Documentation/process/deprecated.rst. strncpy NUL-pads the destination
buffer and doesn't guarantee the destination buffer will be NUL
terminated.
Signed-off-by: James Flowers <bold.zone2373@fastmail.com>
---
V1 -> V2: Replaced with two argument version of strscpy
Note: this has only been compile tested.
net/smc/smc_pnet.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/smc/smc_pnet.c b/net/smc/smc_pnet.c
index 76ad29e31d60..b90337f86e83 100644
--- a/net/smc/smc_pnet.c
+++ b/net/smc/smc_pnet.c
@@ -450,7 +450,7 @@ static int smc_pnet_add_ib(struct smc_pnettable *pnettable, char *ib_name,
return -ENOMEM;
new_pe->type = SMC_PNET_IB;
memcpy(new_pe->pnet_name, pnet_name, SMC_MAX_PNETID_LEN);
- strncpy(new_pe->ib_name, ib_name, IB_DEVICE_NAME_MAX);
+ strscpy(new_pe->ib_name, ib_name);
new_pe->ib_port = ib_port;
new_ibdev = true;
--
2.50.1
On 01/09/25 8:34 am, James Flowers wrote: > strncpy is deprecated for use on NUL-terminated strings, as indicated in > Documentation/process/deprecated.rst. strncpy NUL-pads the destination > buffer and doesn't guarantee the destination buffer will be NUL > terminated. > > Signed-off-by: James Flowers <bold.zone2373@fastmail.com> > --- > V1 -> V2: Replaced with two argument version of strscpy > Note: this has only been compile tested. > > net/smc/smc_pnet.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/net/smc/smc_pnet.c b/net/smc/smc_pnet.c > index 76ad29e31d60..b90337f86e83 100644 > --- a/net/smc/smc_pnet.c > +++ b/net/smc/smc_pnet.c > @@ -450,7 +450,7 @@ static int smc_pnet_add_ib(struct smc_pnettable *pnettable, char *ib_name, > return -ENOMEM; > new_pe->type = SMC_PNET_IB; > memcpy(new_pe->pnet_name, pnet_name, SMC_MAX_PNETID_LEN); > - strncpy(new_pe->ib_name, ib_name, IB_DEVICE_NAME_MAX); > + strscpy(new_pe->ib_name, ib_name); I tested your changes by creating a Software PNET ID using *smc_pnet* tool & it works fine. Your changes are similar to ae2402b(net/smc: replace strncpy with strscpy) commit. Reviewed-by: Mahanta Jambigi <mjambigi@linux.ibm.com> > new_pe->ib_port = ib_port; > > new_ibdev = true;
On Mon, Sep 1, 2025, at 11:40 PM, Mahanta Jambigi wrote: > On 01/09/25 8:34 am, James Flowers wrote: >> strncpy is deprecated for use on NUL-terminated strings, as indicated in >> Documentation/process/deprecated.rst. strncpy NUL-pads the destination >> buffer and doesn't guarantee the destination buffer will be NUL >> terminated. >> >> Signed-off-by: James Flowers <bold.zone2373@fastmail.com> >> --- >> V1 -> V2: Replaced with two argument version of strscpy >> Note: this has only been compile tested. >> >> net/smc/smc_pnet.c | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/net/smc/smc_pnet.c b/net/smc/smc_pnet.c >> index 76ad29e31d60..b90337f86e83 100644 >> --- a/net/smc/smc_pnet.c >> +++ b/net/smc/smc_pnet.c >> @@ -450,7 +450,7 @@ static int smc_pnet_add_ib(struct smc_pnettable *pnettable, char *ib_name, >> return -ENOMEM; >> new_pe->type = SMC_PNET_IB; >> memcpy(new_pe->pnet_name, pnet_name, SMC_MAX_PNETID_LEN); >> - strncpy(new_pe->ib_name, ib_name, IB_DEVICE_NAME_MAX); >> + strscpy(new_pe->ib_name, ib_name); > > I tested your changes by creating a Software PNET ID using *smc_pnet* > tool & it works fine. Your changes are similar to ae2402b(net/smc: > replace strncpy with strscpy) commit. > > Reviewed-by: Mahanta Jambigi <mjambigi@linux.ibm.com> > >> new_pe->ib_port = ib_port; >> >> new_ibdev = true; Thank you for doing that test, Mahanta. Thanks to all who have reviewed so far. Best regards, James Flowers
On 2025-08-31 20:04:59, James Flowers wrote: >strncpy is deprecated for use on NUL-terminated strings, as indicated in >Documentation/process/deprecated.rst. strncpy NUL-pads the destination >buffer and doesn't guarantee the destination buffer will be NUL >terminated. > >Signed-off-by: James Flowers <bold.zone2373@fastmail.com> Reviewed-by: Dust Li <dust.li@linux.alibaba.com> Best regards, Dust >--- >V1 -> V2: Replaced with two argument version of strscpy >Note: this has only been compile tested. > > net/smc/smc_pnet.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > >diff --git a/net/smc/smc_pnet.c b/net/smc/smc_pnet.c >index 76ad29e31d60..b90337f86e83 100644 >--- a/net/smc/smc_pnet.c >+++ b/net/smc/smc_pnet.c >@@ -450,7 +450,7 @@ static int smc_pnet_add_ib(struct smc_pnettable *pnettable, char *ib_name, > return -ENOMEM; > new_pe->type = SMC_PNET_IB; > memcpy(new_pe->pnet_name, pnet_name, SMC_MAX_PNETID_LEN); >- strncpy(new_pe->ib_name, ib_name, IB_DEVICE_NAME_MAX); >+ strscpy(new_pe->ib_name, ib_name); > new_pe->ib_port = ib_port; > > new_ibdev = true; >-- >2.50.1
On Sun, Aug 31, 2025 at 08:04:59PM -0700, James Flowers wrote: > strncpy is deprecated for use on NUL-terminated strings, as indicated in > Documentation/process/deprecated.rst. strncpy NUL-pads the destination > buffer and doesn't guarantee the destination buffer will be NUL > terminated. > > Signed-off-by: James Flowers <bold.zone2373@fastmail.com> > --- > V1 -> V2: Replaced with two argument version of strscpy > Note: this has only been compile tested. Reviewed-by: Simon Horman <horms@kernel.org>
© 2016 - 2025 Red Hat, Inc.