summaryrefslogtreecommitdiffstats
path: root/src/account/LMI_AccountProvider.c
diff options
context:
space:
mode:
authorRoman Rakus <rrakus@redhat.com>2013-09-04 15:25:02 +0200
committerRoman Rakus <rrakus@redhat.com>2013-09-04 16:45:15 +0200
commit23c7f0b6a4dbd86b6e80ba095110742ef79e7a28 (patch)
treef70e4ca7d22ab0f564f87913476267d382fe9c71 /src/account/LMI_AccountProvider.c
parent66fee3cfd9736b860872f0e6a757f11404015193 (diff)
downloadopenlmi-providers-23c7f0b6a4dbd86b6e80ba095110742ef79e7a28.tar.gz
openlmi-providers-23c7f0b6a4dbd86b6e80ba095110742ef79e7a28.tar.xz
openlmi-providers-23c7f0b6a4dbd86b6e80ba095110742ef79e7a28.zip
Account: Fix memory corruption
There was false assumption that lu_end doesn't free error messages. The code is restructured to copy error message to temporary string holder, which is freed after and error message is correctly returned, all in one place. Signed-off-by: Roman Rakus <rrakus@redhat.com>
Diffstat (limited to 'src/account/LMI_AccountProvider.c')
-rw-r--r--src/account/LMI_AccountProvider.c45
1 files changed, 28 insertions, 17 deletions
diff --git a/src/account/LMI_AccountProvider.c b/src/account/LMI_AccountProvider.c
index c58b001..c7c16bb 100644
--- a/src/account/LMI_AccountProvider.c
+++ b/src/account/LMI_AccountProvider.c
@@ -263,6 +263,9 @@ static CMPIStatus LMI_AccountModifyInstance(
date_time_prop expiration, warning, inactive_password, inactive_account;
date_time_prop possible_change;
+ CMPIrc rc = CMPI_RC_OK;
+ char *errmsg = NULL;
+
LMI_Account la;
LMI_Account_InitFromObjectPath(&la, _cb, cop);
@@ -277,10 +280,10 @@ static CMPIStatus LMI_AccountModifyInstance(
lue = lu_ent_new();
if (!lu_user_lookup_name(luc, la.Name.chars, lue, &error))
{
- lu_end(luc);
- lu_ent_free(lue);
- KReturn2(_cb, ERR_NOT_FOUND, "User %s not found: %s",
- la.Name.chars, lu_strerror(error));
+ rc = CMPI_RC_ERR_NOT_FOUND;
+ asprintf(&errmsg, "User %s not found: %s",
+ la.Name.chars, lu_strerror(error));
+ goto fail;
}
data = ci->ft->getProperty(ci, "UserPassword", NULL);
@@ -294,10 +297,10 @@ static CMPIStatus LMI_AccountModifyInstance(
{
if (!lu_user_setpass(luc, lue, value, TRUE, &error))
{
- lu_end(luc);
- lu_ent_free(lue);
- KReturn2(_cb, ERR_FAILED, "Error setting password: %s",
- lu_strerror(error));
+ rc = CMPI_RC_ERR_FAILED;
+ asprintf(&errmsg, "Error setting password: %s",
+ lu_strerror(error));
+ goto fail;
}
}
}
@@ -305,10 +308,10 @@ static CMPIStatus LMI_AccountModifyInstance(
{
if (!lu_user_removepass(luc, lue, &error))
{
- lu_end(luc);
- lu_ent_free(lue);
- KReturn2(_cb, ERR_FAILED, "Error removing password: %s",
- lu_strerror(error));
+ rc = CMPI_RC_ERR_FAILED;
+ asprintf(&errmsg, "Error removing password: %s",
+ lu_strerror(error));
+ goto fail;
}
}
@@ -442,15 +445,23 @@ static CMPIStatus LMI_AccountModifyInstance(
if (!lu_user_modify(luc, lue, &error))
{
- lu_end(luc);
- lu_ent_free(lue);
- KReturn2(_cb, ERR_FAILED, "User modification failed: %s",
- lu_strerror(error));
+ rc = CMPI_RC_ERR_FAILED;
+ asprintf(&errmsg, "User modification failed: %s",
+ lu_strerror(error));
+ goto fail;
}
+fail:
lu_ent_free(lue);
lu_end(luc);
- CMReturn(CMPI_RC_OK);
+
+ if (errmsg) {
+ CMPIString *errstr = CMNewString(_cb, errmsg, NULL);
+ free(errmsg);
+ CMReturnWithString(rc, errstr);
+ } else {
+ CMReturn(rc);
+ }
}
/*