pgreco / rpms / ipa

Forked from forks/areguera/rpms/ipa 4 years ago
Clone

Blame SOURCES/0009-Fix-various-bugs-in-ipa-opt-counter-and-ipa-otp-last.patch

e3ffab
From f4574e1764e56a3a281bfc0e5aba886c46cadf95 Mon Sep 17 00:00:00 2001
e3ffab
From: Jan Cholasta <jcholast@redhat.com>
e3ffab
Date: Wed, 5 Nov 2014 08:50:26 +0000
e3ffab
Subject: [PATCH] Fix various bugs in ipa-opt-counter and ipa-otp-lasttoken
e3ffab
e3ffab
Fixes a wrong sizeof argument and unchecked return values.
e3ffab
e3ffab
https://fedorahosted.org/freeipa/ticket/4651
e3ffab
e3ffab
Reviewed-By: Alexander Bokovoy <abokovoy@redhat.com>
e3ffab
---
e3ffab
 daemons/ipa-slapi-plugins/ipa-otp-counter/berval.c         |  2 +-
e3ffab
 .../ipa-slapi-plugins/ipa-otp-counter/ipa_otp_counter.c    | 14 +++++++++++---
e3ffab
 .../ipa-otp-lasttoken/ipa_otp_lasttoken.c                  |  6 +++++-
e3ffab
 3 files changed, 17 insertions(+), 5 deletions(-)
e3ffab
e3ffab
diff --git a/daemons/ipa-slapi-plugins/ipa-otp-counter/berval.c b/daemons/ipa-slapi-plugins/ipa-otp-counter/berval.c
e3ffab
index 884e1a21004c5440f3bbad9da57d43bba8649d5f..a2fe592f07746423b12d9a531d7860615b729afa 100644
e3ffab
--- a/daemons/ipa-slapi-plugins/ipa-otp-counter/berval.c
e3ffab
+++ b/daemons/ipa-slapi-plugins/ipa-otp-counter/berval.c
e3ffab
@@ -48,7 +48,7 @@ berval_new_longlong(long long value)
e3ffab
 {
e3ffab
     struct berval *bv;
e3ffab
 
e3ffab
-    bv = (struct berval*) slapi_ch_malloc(sizeof(struct berval*));
e3ffab
+    bv = (struct berval*) slapi_ch_malloc(sizeof(struct berval));
e3ffab
     bv->bv_val = slapi_ch_smprintf("%lld", value);
e3ffab
     bv->bv_len = strlen(bv->bv_val);
e3ffab
 
e3ffab
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
e3ffab
index 24ef9e2401d62d7d63b55afb9aa3ba2f41642839..da047d7dc58e27b37ad29c39bde44e33602ab4c5 100644
e3ffab
--- a/daemons/ipa-slapi-plugins/ipa-otp-counter/ipa_otp_counter.c
e3ffab
+++ b/daemons/ipa-slapi-plugins/ipa-otp-counter/ipa_otp_counter.c
e3ffab
@@ -50,6 +50,7 @@
e3ffab
 
e3ffab
 #include "berval.h"
e3ffab
 #include "ldapmod.h"
e3ffab
+#include "util.h"
e3ffab
 
e3ffab
 #include <limits.h>
e3ffab
 
e3ffab
@@ -140,6 +141,7 @@ normalize_input(LDAPMod ***mods, const char *attr, long long ctr)
e3ffab
         case LDAP_MOD_REPLACE:
e3ffab
         case LDAP_MOD_INCREMENT:
e3ffab
             e++;
e3ffab
+            /* fall through */
e3ffab
         default:
e3ffab
             c++;
e3ffab
         }
e3ffab
@@ -284,8 +286,12 @@ preop_mod(Slapi_PBlock *pb)
e3ffab
     cpre = get_counter(epre, attr);
e3ffab
 
e3ffab
     if (repl == 0) {
e3ffab
-        if (normalize_input(&mods, attr, cpre) != 0)
e3ffab
-            slapi_pblock_set(pb, SLAPI_MODIFY_MODS, mods);
e3ffab
+        if (normalize_input(&mods, attr, cpre) != 0) {
e3ffab
+            if (slapi_pblock_set(pb, SLAPI_MODIFY_MODS, mods)) {
e3ffab
+                LOG_FATAL("slapi_pblock_set failed!\n");
e3ffab
+                goto error;
e3ffab
+            }
e3ffab
+        }
e3ffab
     }
e3ffab
 
e3ffab
     if (!simulate(mods, attr, cpre, &cpost) && repl == 0) {
e3ffab
@@ -316,7 +322,9 @@ preop_mod(Slapi_PBlock *pb)
e3ffab
 error:
e3ffab
     rc = LDAP_UNWILLING_TO_PERFORM;
e3ffab
     slapi_send_ldap_result(pb, rc, NULL, msg, 0, NULL);
e3ffab
-    slapi_pblock_set(pb, SLAPI_RESULT_CODE, &rc);
e3ffab
+    if (slapi_pblock_set(pb, SLAPI_RESULT_CODE, &rc)) {
e3ffab
+        LOG_FATAL("slapi_pblock_set failed!\n");
e3ffab
+    }
e3ffab
 
e3ffab
     slapi_ch_free_string(&msg;;
e3ffab
     return rc;
e3ffab
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
e3ffab
index 94d24ae0f0383c090e1207c6f4552ea29601f26e..d20fca1e705f7406362a3ba2def9ba102bd1622d 100644
e3ffab
--- a/daemons/ipa-slapi-plugins/ipa-otp-lasttoken/ipa_otp_lasttoken.c
e3ffab
+++ b/daemons/ipa-slapi-plugins/ipa-otp-lasttoken/ipa_otp_lasttoken.c
e3ffab
@@ -44,6 +44,8 @@
e3ffab
 #include <libotp.h>
e3ffab
 #include <time.h>
e3ffab
 
e3ffab
+#include "util.h"
e3ffab
+
e3ffab
 #define PLUGIN_NAME               "ipa-otp-lasttoken"
e3ffab
 #define LOG(sev, ...) \
e3ffab
     slapi_log_error(SLAPI_LOG_ ## sev, PLUGIN_NAME, \
e3ffab
@@ -100,7 +102,9 @@ static inline int
e3ffab
 send_error(Slapi_PBlock *pb, int rc, char *errstr)
e3ffab
 {
e3ffab
     slapi_send_ldap_result(pb, rc, NULL, errstr, 0, NULL);
e3ffab
-    slapi_pblock_set(pb, SLAPI_RESULT_CODE, &rc);
e3ffab
+    if (slapi_pblock_set(pb, SLAPI_RESULT_CODE, &rc)) {
e3ffab
+        LOG_FATAL("slapi_pblock_set failed!\n");
e3ffab
+    }
e3ffab
     return rc;
e3ffab
 }
e3ffab
 
e3ffab
-- 
e3ffab
2.1.0
e3ffab