git.samba.org
/
sfrench
/
cifs-2.6.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
ed94172
)
bna: replace deprecated strncpy with strscpy_pad
author
Justin Stitt
<justinstitt@google.com>
Mon, 9 Oct 2023 17:45:33 +0000
(17:45 +0000)
committer
Jakub Kicinski
<kuba@kernel.org>
Thu, 12 Oct 2023 00:26:14 +0000
(17:26 -0700)
`strncpy` is deprecated for use on NUL-terminated destination strings
[1] and as such we should prefer more robust and less ambiguous string
interfaces.
bfa_ioc_get_adapter_manufacturer() simply copies a string literal into
`manufacturer`.
Another implementation of bfa_ioc_get_adapter_manufacturer() from
drivers/scsi/bfa/bfa_ioc.c uses memset + strscpy:
| void
| bfa_ioc_get_adapter_manufacturer(struct bfa_ioc_s *ioc, char *manufacturer)
| {
| memset((void *)manufacturer, 0, BFA_ADAPTER_MFG_NAME_LEN);
| strscpy(manufacturer, BFA_MFG_NAME, BFA_ADAPTER_MFG_NAME_LEN);
| }
Let's use `strscpy_pad` to eliminate some redundant work while still
NUL-terminating and NUL-padding the destination buffer.
Link:
https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings
Link:
https://github.com/KSPP/linux/issues/90
Signed-off-by: Justin Stitt <justinstitt@google.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
Link:
https://lore.kernel.org/r/20231009-strncpy-drivers-net-ethernet-brocade-bna-bfa_ioc-c-v2-1-78e0f47985d3@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/brocade/bna/bfa_ioc.c
patch
|
blob
|
history
diff --git
a/drivers/net/ethernet/brocade/bna/bfa_ioc.c
b/drivers/net/ethernet/brocade/bna/bfa_ioc.c
index b07522ac3e74ea16df7d8378285736b71082560d..9c80ab07a7357205237ee5b0af56c7871712f2ec 100644
(file)
--- a/
drivers/net/ethernet/brocade/bna/bfa_ioc.c
+++ b/
drivers/net/ethernet/brocade/bna/bfa_ioc.c
@@
-2839,7
+2839,7
@@
bfa_ioc_get_adapter_optrom_ver(struct bfa_ioc *ioc, char *optrom_ver)
static void
bfa_ioc_get_adapter_manufacturer(struct bfa_ioc *ioc, char *manufacturer)
{
- str
ncpy
(manufacturer, BFA_MFG_NAME, BFA_ADAPTER_MFG_NAME_LEN);
+ str
scpy_pad
(manufacturer, BFA_MFG_NAME, BFA_ADAPTER_MFG_NAME_LEN);
}
static void