pgreco / rpms / ipa

Forked from forks/areguera/rpms/ipa 4 years ago
Clone
Blob Blame History Raw
From f4574e1764e56a3a281bfc0e5aba886c46cadf95 Mon Sep 17 00:00:00 2001
From: Jan Cholasta <jcholast@redhat.com>
Date: Wed, 5 Nov 2014 08:50:26 +0000
Subject: [PATCH] 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>
---
 daemons/ipa-slapi-plugins/ipa-otp-counter/berval.c         |  2 +-
 .../ipa-slapi-plugins/ipa-otp-counter/ipa_otp_counter.c    | 14 +++++++++++---
 .../ipa-otp-lasttoken/ipa_otp_lasttoken.c                  |  6 +++++-
 3 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/daemons/ipa-slapi-plugins/ipa-otp-counter/berval.c b/daemons/ipa-slapi-plugins/ipa-otp-counter/berval.c
index 884e1a21004c5440f3bbad9da57d43bba8649d5f..a2fe592f07746423b12d9a531d7860615b729afa 100644
--- a/daemons/ipa-slapi-plugins/ipa-otp-counter/berval.c
+++ b/daemons/ipa-slapi-plugins/ipa-otp-counter/berval.c
@@ -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);
 
diff --git a/daemons/ipa-slapi-plugins/ipa-otp-counter/ipa_otp_counter.c b/daemons/ipa-slapi-plugins/ipa-otp-counter/ipa_otp_counter.c
index 24ef9e2401d62d7d63b55afb9aa3ba2f41642839..da047d7dc58e27b37ad29c39bde44e33602ab4c5 100644
--- a/daemons/ipa-slapi-plugins/ipa-otp-counter/ipa_otp_counter.c
+++ b/daemons/ipa-slapi-plugins/ipa-otp-counter/ipa_otp_counter.c
@@ -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;
diff --git a/daemons/ipa-slapi-plugins/ipa-otp-lasttoken/ipa_otp_lasttoken.c b/daemons/ipa-slapi-plugins/ipa-otp-lasttoken/ipa_otp_lasttoken.c
index 94d24ae0f0383c090e1207c6f4552ea29601f26e..d20fca1e705f7406362a3ba2def9ba102bd1622d 100644
--- a/daemons/ipa-slapi-plugins/ipa-otp-lasttoken/ipa_otp_lasttoken.c
+++ b/daemons/ipa-slapi-plugins/ipa-otp-lasttoken/ipa_otp_lasttoken.c
@@ -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;
 }
 
-- 
2.1.0