Commit 9cb46a2
committed
Correct string length handling in strlimcpy in halcmd.c
The strlen value is the string length, often fetched from strlen(),
which return the number of characters in the string, excluding the
terminal NUL character. To have room to copy the string into *dest,
the *destspace available must be strlen+1, not strlen, to also have
room for the NUL at the end. Setting NUL explicitly will not be
needed in the case srclen reflect the real length of str, but if srclen
is smaller than the real length of str, will will ensure the string
is always NUL terminated. Pass *destspace instead of strlen+1 to
strncpy() ensure the actual target size limit is used no matter what
the content of srclen is.1 parent 973ecc3 commit 9cb46a2
1 file changed
+2
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
678 | 678 | | |
679 | 679 | | |
680 | 680 | | |
681 | | - | |
| 681 | + | |
682 | 682 | | |
683 | 683 | | |
684 | | - | |
| 684 | + | |
685 | 685 | | |
686 | 686 | | |
687 | 687 | | |
| |||
0 commit comments