BIND 10 trac2342, updated. 08daa03beac5d16305734fc434edcc28962205e9 [2342] Add check that database name cannot be NULL
BIND 10 source code commits
bind10-changes at lists.isc.org
Wed Oct 24 18:35:11 UTC 2012
The branch, trac2342 has been updated
via 08daa03beac5d16305734fc434edcc28962205e9 (commit)
from 39c82ec533e3642015ce742a132b31350e91c928 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 08daa03beac5d16305734fc434edcc28962205e9
Author: Stephen Morris <stephen at isc.org>
Date: Wed Oct 24 19:34:38 2012 +0100
[2342] Add check that database name cannot be NULL
-----------------------------------------------------------------------
Summary of changes:
src/lib/dhcp/lease_mgr.h | 7 ++++
src/lib/dhcp/mysql_lease_mgr.cc | 4 +--
src/lib/dhcp/mysql_lease_mgr.h | 2 ++
src/lib/dhcp/tests/mysql_lease_mgr_unittest.cc | 45 ++++++++++++++++++++++--
4 files changed, 54 insertions(+), 4 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/lib/dhcp/lease_mgr.h b/src/lib/dhcp/lease_mgr.h
index 6d74e5e..c21b996 100644
--- a/src/lib/dhcp/lease_mgr.h
+++ b/src/lib/dhcp/lease_mgr.h
@@ -61,6 +61,13 @@
namespace isc {
namespace dhcp {
+/// @brief Exception thrown if name of database is not specified
+class NoDatabaseName : public Exception {
+public:
+ NoDatabaseName(const char* file, size_t line, const char* what) :
+ isc::Exception(file, line, what) {}
+};
+
/// @brief Exception thrown on failure to open database
class DbOpenError : public Exception {
public:
diff --git a/src/lib/dhcp/mysql_lease_mgr.cc b/src/lib/dhcp/mysql_lease_mgr.cc
index 8fb73bd..5f5fedd 100644
--- a/src/lib/dhcp/mysql_lease_mgr.cc
+++ b/src/lib/dhcp/mysql_lease_mgr.cc
@@ -471,8 +471,8 @@ MySqlLeaseMgr::openDatabase() {
sname = getParameter("name");
name = sname.c_str();
} catch (...) {
- // No database name. Fine, we'll use NULL
- ;
+ // No database name. Throw a "NoName" exception
+ isc_throw(NoDatabaseName, "must specified a name for the database");
}
// Open the database. Use defaults for non-specified options.
diff --git a/src/lib/dhcp/mysql_lease_mgr.h b/src/lib/dhcp/mysql_lease_mgr.h
index 349b3bb..9a86691 100644
--- a/src/lib/dhcp/mysql_lease_mgr.h
+++ b/src/lib/dhcp/mysql_lease_mgr.h
@@ -45,6 +45,7 @@ public:
/// @param parameters A data structure relating keywords and values
/// concerned with the database.
///
+ /// @exception NoDatabaseName Mandatory database name not given
/// @exception DbOpenError Error opening the database
/// @exception DbOperationError An operation on the open database has
/// failed.
@@ -362,6 +363,7 @@ private:
/// Opens the database using the information supplied in the parameters
/// passed to the constructor.
///
+ /// @exception NoDatabaseName Mandatory database name not given
/// @exception DbOpenError Error opening the database
void openDatabase();
diff --git a/src/lib/dhcp/tests/mysql_lease_mgr_unittest.cc b/src/lib/dhcp/tests/mysql_lease_mgr_unittest.cc
index e8305e4..c0f12a4 100644
--- a/src/lib/dhcp/tests/mysql_lease_mgr_unittest.cc
+++ b/src/lib/dhcp/tests/mysql_lease_mgr_unittest.cc
@@ -46,8 +46,41 @@ const char* INVALID_PASSWORD = "password=invalid";
string connectionString(const char* type, const char* name, const char* host,
const char* user, const char* password) {
const string space = " ";
- return (string(type) + space + string(name) + space + string(host) + space +
- string(user) + space + string(password));
+ string result = "";
+
+ if (type != NULL) {
+ result += string(type);
+ }
+
+ if (name != NULL) {
+ if (! result.empty()) {
+ result += space;
+ }
+ result += string(name);
+ }
+
+ if (host != NULL) {
+ if (! result.empty()) {
+ result += space;
+ }
+ result += string(host);
+ }
+
+ if (user != NULL) {
+ if (! result.empty()) {
+ result += space;
+ }
+ result += string(user);
+ }
+
+ if (password != NULL) {
+ if (! result.empty()) {
+ result += space;
+ }
+ result += string(password);
+ }
+
+ return (result);
}
// Return valid connection string
@@ -102,6 +135,9 @@ TEST(MySqlOpenTest, OpenDatabase) {
// (This is really a check on LeaseMgrFactory, but is convenient to
// perform here.)
EXPECT_THROW(LeaseMgrFactory::create(connectionString(
+ NULL, VALID_NAME, VALID_HOST, INVALID_USER, VALID_PASSWORD)),
+ InvalidParameter);
+ EXPECT_THROW(LeaseMgrFactory::create(connectionString(
INVALID_TYPE, VALID_NAME, VALID_HOST, VALID_USER, VALID_PASSWORD)),
InvalidType);
@@ -119,6 +155,11 @@ TEST(MySqlOpenTest, OpenDatabase) {
VALID_TYPE, VALID_NAME, VALID_HOST, VALID_USER, INVALID_PASSWORD)),
DbOpenError);
+ // Check for missing parameters
+ EXPECT_THROW(LeaseMgrFactory::create(connectionString(
+ VALID_TYPE, NULL, VALID_HOST, INVALID_USER, VALID_PASSWORD)),
+ NoDatabaseName);
+
// Check that database opens correctly.
ASSERT_NO_THROW(LeaseMgrFactory::create(validConnectionString()));
EXPECT_NO_THROW((void) LeaseMgrFactory::instance());
More information about the bind10-changes
mailing list