mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
ipa_sam: do not modify static buffer holding fqdn
ipa_sam was modifying the buffer returned by ipa_gethostfqdn(). Subsequent calls to ipa_gethostfqdn() returned the corrupt data, causing other operations to fail. Update ipa_sam to copy the string and modify the copy. Also document this characteristic of ipa_gethostfqdn() and explain that callers must not modify the returned data. Part of: https://pagure.io/freeipa/issue/8501 Reviewed-By: Fraser Tweedale <ftweedal@redhat.com>
This commit is contained in:
parent
727a2ffb93
commit
3f59118ffc
@ -4441,7 +4441,8 @@ static char *sec_key(TALLOC_CTX *mem_ctx, const char *d)
|
||||
|
||||
static NTSTATUS save_sid_to_secret(struct ipasam_private *ipasam_state)
|
||||
{
|
||||
const char *hostname;
|
||||
char hostname[IPA_HOST_FQDN_LEN];
|
||||
const char *fqdn;
|
||||
char *p;
|
||||
TALLOC_CTX *tmp_ctx;
|
||||
NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
|
||||
@ -4466,12 +4467,15 @@ static NTSTATUS save_sid_to_secret(struct ipasam_private *ipasam_state)
|
||||
goto done;
|
||||
}
|
||||
|
||||
hostname = ipa_gethostfqdn();
|
||||
if (hostname == NULL) {
|
||||
fqdn = ipa_gethostfqdn();
|
||||
if (fqdn == NULL) {
|
||||
DEBUG(1, ("ipa_gethostfqdn failed.\n"));
|
||||
status = NT_STATUS_UNSUCCESSFUL;
|
||||
goto done;
|
||||
}
|
||||
/* Copy is necessary, otherwise we this will corrupt the static
|
||||
* buffer returned by ipa_gethostfqdn(). */
|
||||
strncpy(hostname, fqdn, sizeof(hostname));
|
||||
p = strchr(hostname, '.');
|
||||
if (p != NULL) {
|
||||
*p = '\0';
|
||||
|
@ -11,5 +11,12 @@
|
||||
*/
|
||||
#define IPA_HOST_FQDN_LEN 255
|
||||
|
||||
/* Get the host FQDN.
|
||||
*
|
||||
* Returns a null-terminated static char[]. The string length is
|
||||
* at most IPA_HOST_FQDN_LEN - 1. The caller MUST NOT modify this
|
||||
* buffer. If modification could occur, the caller MUST copy
|
||||
* the string.
|
||||
*/
|
||||
const char*
|
||||
ipa_gethostfqdn(void);
|
||||
|
Loading…
Reference in New Issue
Block a user