Blame SOURCES/0015-Ticket-49408-Server-allows-to-set-any-nsds5replicaid.patch

96373c
From 4569da8f2c55d54a34f31312ee5756c70a7f463c Mon Sep 17 00:00:00 2001
96373c
From: Mark Reynolds <mreynolds@redhat.com>
96373c
Date: Thu, 19 Oct 2017 17:33:10 -0400
96373c
Subject: [PATCH] Ticket 49408 - Server allows to set any nsds5replicaid in the
96373c
 existing replica entry
96373c
96373c
Description:  There was no value validation for replica ID.  Now there is.
96373c
96373c
https://pagure.io/389-ds-base/issue/49408
96373c
96373c
Reviewed by: tbordaz(Thanks!)
96373c
96373c
(cherry picked from commit 296f0abb78b7ec82580d039d9c505506f6ce07be)
96373c
---
96373c
 ldap/servers/plugins/replication/repl5_replica_config.c | 12 ++++++++++++
96373c
 1 file changed, 12 insertions(+)
96373c
96373c
diff --git a/ldap/servers/plugins/replication/repl5_replica_config.c b/ldap/servers/plugins/replication/repl5_replica_config.c
96373c
index 22d766143..7477a292c 100644
96373c
--- a/ldap/servers/plugins/replication/repl5_replica_config.c
96373c
+++ b/ldap/servers/plugins/replication/repl5_replica_config.c
96373c
@@ -411,6 +411,18 @@ replica_config_modify(Slapi_PBlock *pb,
96373c
                     slapi_ch_free_string(&new_repl_type);
96373c
                     new_repl_type = slapi_ch_strdup(config_attr_value);
96373c
                 } else if (strcasecmp(config_attr, attr_replicaId) == 0) {
96373c
+                    char *endp = NULL;
96373c
+                    int64_t rid = 0;
96373c
+                    errno = 0;
96373c
+                    rid = strtoll(config_attr_value, &endp, 10);
96373c
+                    if (*endp != '\0' || rid > 65535 || rid < 1 || errno == ERANGE) {
96373c
+                        *returncode = LDAP_UNWILLING_TO_PERFORM;
96373c
+                        PR_snprintf(errortext, SLAPI_DSE_RETURNTEXT_SIZE,
96373c
+                            "Attribute %s value (%s) is invalid, must be a number between 1 and 65535.\n",
96373c
+                            config_attr, config_attr_value);
96373c
+                        slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name, "replica_config_modify - %s\n", errortext);
96373c
+                        break;
96373c
+                    }
96373c
                     slapi_ch_free_string(&new_repl_id);
96373c
                     new_repl_id = slapi_ch_strdup(config_attr_value);
96373c
                 } else if (strcasecmp(config_attr, attr_flags) == 0) {
96373c
-- 
96373c
2.13.6
96373c