From 84a4386fa03406d32ca9dfcaa9bd4956f190fcb0 Mon Sep 17 00:00:00 2001 From: Stephen Gallagher Date: Thu, 10 Sep 2009 11:07:25 -0400 Subject: [PATCH 3/3] Properly detect negative/invalid values for the minId and maxId --- server/confdb/confdb.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 46 insertions(+), 2 deletions(-) diff --git a/server/confdb/confdb.c b/server/confdb/confdb.c index e3fc672..d21684a 100644 --- a/server/confdb/confdb.c +++ b/server/confdb/confdb.c @@ -21,6 +21,7 @@ #define _GNU_SOURCE +#include #include "config.h" #include "util/util.h" #include "confdb/confdb.h" @@ -672,6 +673,37 @@ int confdb_init(TALLOC_CTX *mem_ctx, return EOK; } +enum confdb_int_entry_type { + CONFDB_INT_ENTRY_TYPE_NaN, + CONFDB_INT_ENTRY_TYPE_NOEXIST, + CONFDB_INT_ENTRY_TYPE_POS, + CONFDB_INT_ENTRY_TYPE_NEG, +}; + +static enum confdb_int_entry_type entry_is_int(struct ldb_message *msg, + const char *entry) +{ + const char *tmp = NULL; + bool positive = true; + + tmp = ldb_msg_find_attr_as_string(msg, entry, NULL); + if (tmp == NULL) { + return CONFDB_INT_ENTRY_TYPE_NOEXIST; + } + + if (tmp[0] == '-') { + positive = false; + tmp++; + } + while (*tmp != '\0') { + if (!isdigit(*tmp)) { + return CONFDB_INT_ENTRY_TYPE_NaN; + } + tmp++; + } + return positive?CONFDB_INT_ENTRY_TYPE_POS:CONFDB_INT_ENTRY_TYPE_NEG; +} + static int confdb_get_domain_internal(struct confdb_ctx *cdb, TALLOC_CTX *mem_ctx, const char *name, @@ -779,12 +811,24 @@ static int confdb_get_domain_internal(struct confdb_ctx *cdb, domain->fqnames = true; } + if(entry_is_int(res->msgs[0], "minId") != CONFDB_INT_ENTRY_TYPE_POS) { + DEBUG(0, ("Invalid value for minId\n")); + ret = EINVAL; + goto done; + } + + if(entry_is_int(res->msgs[0], "maxId") != CONFDB_INT_ENTRY_TYPE_POS) { + DEBUG(0, ("Invalid value for maxId\n")); + ret = EINVAL; + goto done; + } + domain->id_min = ldb_msg_find_attr_as_uint(res->msgs[0], "minId", SSSD_MIN_ID); domain->id_max = ldb_msg_find_attr_as_uint(res->msgs[0], "maxId", 0); - if ((domain->id_max && (domain->id_max < domain->id_min)) || - (domain->id_min < 0)){ + if (domain->id_max && (domain->id_max < domain->id_min)) { + DEBUG(0, ("Invalid domain range\n")); ret = EINVAL; goto done; } -- 1.6.2.5