Commit b00839c
ipmi: refactor deprecated strncpy
`strncpy` is deprecated for use on NUL-terminated destination strings [1].
In this case, strncpy is being used specifically for its NUL-padding
behavior (and has been commented as such). Moreover, the destination
string is not required to be NUL-terminated [2].
We can use a more robust and less ambiguous interface in
`memcpy_and_pad` which makes the code more readable and even eliminates
the need for that comment.
Let's also use `strnlen` instead of `strlen()` with an upper-bounds
check as this is intrinsically a part of `strnlen`.
Also included in this patch is a simple 1:1 change of `strncpy` to
`strscpy` for ipmi_ssif.c. If NUL-padding is wanted here as well then we
should opt again for `strscpy_pad`.
Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings [1]
Link: https://lore.kernel.org/all/[email protected]/ [2]
Link: KSPP/linux#90
Cc: [email protected]
Cc: Kees Cook <[email protected]>
Signed-off-by: Justin Stitt <[email protected]>
Message-Id: <20230913-strncpy-drivers-char-ipmi-ipmi-v2-1-e3bc0f6e599f@google.com>
Signed-off-by: Corey Minyard <[email protected]>1 parent 3669558 commit b00839c
2 files changed
+4
-9
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5377 | 5377 | | |
5378 | 5378 | | |
5379 | 5379 | | |
5380 | | - | |
| 5380 | + | |
5381 | 5381 | | |
5382 | | - | |
5383 | | - | |
5384 | 5382 | | |
5385 | 5383 | | |
5386 | 5384 | | |
5387 | 5385 | | |
5388 | 5386 | | |
5389 | | - | |
5390 | | - | |
5391 | | - | |
5392 | | - | |
5393 | | - | |
| 5387 | + | |
| 5388 | + | |
5394 | 5389 | | |
5395 | 5390 | | |
5396 | 5391 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1945 | 1945 | | |
1946 | 1946 | | |
1947 | 1947 | | |
1948 | | - | |
| 1948 | + | |
1949 | 1949 | | |
1950 | 1950 | | |
1951 | 1951 | | |
| |||
0 commit comments