From 4ca3120b9a09ad48866446af29b38ca7c005b0d0 Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Oct 24 2018 15:46:46 +0000 Subject: 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 Reviewed-By: Alexander Bokovoy --- diff --git a/daemons/ipa-kdb/ipa_kdb.c b/daemons/ipa-kdb/ipa_kdb.c index 00c7326..2096731 100644 --- a/daemons/ipa-kdb/ipa_kdb.c +++ b/daemons/ipa-kdb/ipa_kdb.c @@ -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; diff --git a/daemons/ipa-slapi-plugins/ipa-pwd-extop/common.c b/daemons/ipa-slapi-plugins/ipa-pwd-extop/common.c index db7183b..61b4690 100644 --- a/daemons/ipa-slapi-plugins/ipa-pwd-extop/common.c +++ b/daemons/ipa-slapi-plugins/ipa-pwd-extop/common.c @@ -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;