URL: https://github.com/freeipa/freeipa/pull/2469
Author: t-woerner
Title: #2469: Fix C issues found by coverity and others
Action: opened
PR body:
"""
Two issues have been addressed:
Fix ressource leak in
daemons/ipa-slapi-plugins/ipa-cldap/ipa_cldap_netlogon.c ipa_cldap_netlogon
The leak happens due to using strndup in a for loop to create a temporary
string without freeing it in all cases.
and
Fix ressource leak in client/config.c get_config_entry
The leak happens due to using strndup to create a temporary string without
freeing it afterwards.
"""
To pull the PR as Git branch:
git remote add ghfreeipa https://github.com/freeipa/freeipa
git fetch ghfreeipa pull/2469/head:pr2469
git checkout pr2469
From 555171a8b3cafe76307ebcc994c2cfe93b638425 Mon Sep 17 00:00:00 2001
From: Thomas Woerner <[email protected]>
Date: Mon, 22 Oct 2018 13:57:11 +0200
Subject: [PATCH 1/2] Fix ressource leak in client/config.c get_config_entry
The leak happens due to using strndup to create a temporary string without
freeing it afterwards.
See: https://pagure.io/freeipa/issue/7738
Signed-off-by: Thomas Woerner <[email protected]>
---
client/config.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/client/config.c b/client/config.c
index ecc126ff47..7cf85d8b68 100644
--- a/client/config.c
+++ b/client/config.c
@@ -123,17 +123,18 @@ get_config_entry(char * in_data, const char *section, const char *key)
line++;
p = strchr(line, ']');
if (p) {
- tmp = strndup(line, p - line);
if (in_section) {
/* We exited the matching section without a match */
free(data);
return NULL;
}
+ tmp = strndup(line, p - line);
if (strcmp(section, tmp) == 0) {
free(tmp);
in_section = 1;
continue;
}
+ free(tmp);
}
} /* [ */
From 261ab788ffae9f9921bbdcf68479e1f401990ea9 Mon Sep 17 00:00:00 2001
From: Thomas Woerner <[email protected]>
Date: Mon, 22 Oct 2018 15:18:23 +0200
Subject: [PATCH 2/2] Fix ressource leak in
daemons/ipa-slapi-plugins/ipa-cldap/ipa_cldap_netlogon.c ipa_cldap_netlogon
The leak happens due to using strndup in a for loop to create a temporary
string without freeing it in all cases.
See: https://pagure.io/freeipa/issue/7738
Signed-off-by: Thomas Woerner <[email protected]>
---
daemons/ipa-slapi-plugins/ipa-cldap/ipa_cldap_netlogon.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/daemons/ipa-slapi-plugins/ipa-cldap/ipa_cldap_netlogon.c b/daemons/ipa-slapi-plugins/ipa-cldap/ipa_cldap_netlogon.c
index 5863f667ea..907e4f51d3 100644
--- a/daemons/ipa-slapi-plugins/ipa-cldap/ipa_cldap_netlogon.c
+++ b/daemons/ipa-slapi-plugins/ipa-cldap/ipa_cldap_netlogon.c
@@ -260,6 +260,10 @@ int ipa_cldap_netlogon(struct ipa_cldap_ctx *ctx,
if (req->kvps.pairs[i].value.bv_val[len-1] == '.') {
len--;
}
+ if (domain != NULL) {
+ free(domain);
+ domain = NULL;
+ }
domain = strndup(req->kvps.pairs[i].value.bv_val, len);
if (!domain) {
ret = ENOMEM;
@@ -350,6 +354,7 @@ int ipa_cldap_netlogon(struct ipa_cldap_ctx *ctx,
ret = EINVAL;
goto done;
}
+ free(domain);
}
ret = ipa_cldap_encode_netlogon(hostname, our_domain,
_______________________________________________
FreeIPA-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]
Fedora Code of Conduct: https://getfedora.org/code-of-conduct.html
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives:
https://lists.fedorahosted.org/archives/list/[email protected]