From f49818e422b550b5080601e640e6ee5d49c80a81 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 20 Oct 2009 11:34:49 +1100 Subject: lib-util: check for too many combinations in generate_unique_strs() --- lib/util/genrand.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/util/genrand.c b/lib/util/genrand.c index 6002c0647e..f0544023f1 100644 --- a/lib/util/genrand.c +++ b/lib/util/genrand.c @@ -375,7 +375,6 @@ _PUBLIC_ char** generate_unique_strs(TALLOC_CTX *mem_ctx, size_t len, const unsigned c_size = 42; int i, j; unsigned rem; - long long place; char ** strs = NULL; if (num == 0 || len == 0) @@ -397,6 +396,16 @@ _PUBLIC_ char** generate_unique_strs(TALLOC_CTX *mem_ctx, size_t len, } retstr[j] = 0; strs[i] = retstr; + if (rem != 0) { + /* we were not able to fit the number of + * combinations asked for in the length + * specified */ + DEBUG(0,(__location__ ": Too many combinations %u for length %u\n", + num, (unsigned)len)); + + talloc_free(strs); + return NULL; + } } return strs; -- cgit