Don't abuse strncpy() length limitation

On two occasions C code abused strncpy()'s length limitation to copy a
string of known length without the trailing NULL byte. Recent GCC is
raising the compiler warning:

  warning: ‘strncpy’ output truncated before terminating nul copying as
  many bytes from a string as its length [-Wstringop-truncation]

Use memcpy() instead if strncpy() to copy data of known size.

See: https://pagure.io/freeipa/issue/7738
Signed-off-by: Christian Heimes <cheimes@redhat.com>
Reviewed-By: Alexander Bokovoy <abokovoy@redhat.com>
This commit is contained in:
Christian Heimes 2018-10-24 10:19:14 +02:00
parent 836e29591c
commit 5fe3198d80
2 changed files with 2 additions and 2 deletions

View File

@ -110,7 +110,7 @@ static char *ipadb_realm_to_ldapi_uri(char *realm)
/* copy path and escape '/' to '%2f' */
for (q = LDAPIDIR; *q; q++) {
if (*q == '/') {
strncpy(p, "%2f", 3);
memcpy(p, "%2f", 3);
p += 3;
} else {
*p = *q;

View File

@ -1003,7 +1003,7 @@ int ipapwd_set_extradata(const char *dn,
xdata[5] = (unixtime & 0xff000000) >> 24;
/* append the principal name */
strncpy(&xdata[6], principal, p_len);
memcpy(&xdata[6], principal, p_len);
xdata[xd_len -1] = 0;