Fix various bugs in ipa-opt-counter and ipa-otp-lasttoken

Fixes a wrong sizeof argument and unchecked return values.

https://fedorahosted.org/freeipa/ticket/4651

Reviewed-By: Alexander Bokovoy <abokovoy@redhat.com>
This commit is contained in:
Jan Cholasta
2014-11-05 08:50:26 +00:00
committed by Martin Kosek
parent 701dde3cb3
commit 9062dcada4
3 changed files with 17 additions and 5 deletions

View File

@@ -48,7 +48,7 @@ berval_new_longlong(long long value)
{
struct berval *bv;
bv = (struct berval*) slapi_ch_malloc(sizeof(struct berval*));
bv = (struct berval*) slapi_ch_malloc(sizeof(struct berval));
bv->bv_val = slapi_ch_smprintf("%lld", value);
bv->bv_len = strlen(bv->bv_val);

View File

@@ -50,6 +50,7 @@
#include "berval.h"
#include "ldapmod.h"
#include "util.h"
#include <limits.h>
@@ -140,6 +141,7 @@ normalize_input(LDAPMod ***mods, const char *attr, long long ctr)
case LDAP_MOD_REPLACE:
case LDAP_MOD_INCREMENT:
e++;
/* fall through */
default:
c++;
}
@@ -284,8 +286,12 @@ preop_mod(Slapi_PBlock *pb)
cpre = get_counter(epre, attr);
if (repl == 0) {
if (normalize_input(&mods, attr, cpre) != 0)
slapi_pblock_set(pb, SLAPI_MODIFY_MODS, mods);
if (normalize_input(&mods, attr, cpre) != 0) {
if (slapi_pblock_set(pb, SLAPI_MODIFY_MODS, mods)) {
LOG_FATAL("slapi_pblock_set failed!\n");
goto error;
}
}
}
if (!simulate(mods, attr, cpre, &cpost) && repl == 0) {
@@ -316,7 +322,9 @@ preop_mod(Slapi_PBlock *pb)
error:
rc = LDAP_UNWILLING_TO_PERFORM;
slapi_send_ldap_result(pb, rc, NULL, msg, 0, NULL);
slapi_pblock_set(pb, SLAPI_RESULT_CODE, &rc);
if (slapi_pblock_set(pb, SLAPI_RESULT_CODE, &rc)) {
LOG_FATAL("slapi_pblock_set failed!\n");
}
slapi_ch_free_string(&msg);
return rc;

View File

@@ -44,6 +44,8 @@
#include <libotp.h>
#include <time.h>
#include "util.h"
#define PLUGIN_NAME "ipa-otp-lasttoken"
#define LOG(sev, ...) \
slapi_log_error(SLAPI_LOG_ ## sev, PLUGIN_NAME, \
@@ -100,7 +102,9 @@ static inline int
send_error(Slapi_PBlock *pb, int rc, char *errstr)
{
slapi_send_ldap_result(pb, rc, NULL, errstr, 0, NULL);
slapi_pblock_set(pb, SLAPI_RESULT_CODE, &rc);
if (slapi_pblock_set(pb, SLAPI_RESULT_CODE, &rc)) {
LOG_FATAL("slapi_pblock_set failed!\n");
}
return rc;
}