From: Marcin Siodelski Date: Wed, 4 Mar 2015 12:32:18 +0000 (+0100) Subject: [3673] Handle overflows in the time conversions in the MySQL backend. X-Git-Tag: trac3764_base~16^2~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8fa9106272bbd8152be0d0c9761010e3ffac6352;p=thirdparty%2Fkea.git [3673] Handle overflows in the time conversions in the MySQL backend. --- diff --git a/src/lib/dhcpsrv/mysql_lease_mgr.cc b/src/lib/dhcpsrv/mysql_lease_mgr.cc index 77a21f4588..13aae60b00 100644 --- a/src/lib/dhcpsrv/mysql_lease_mgr.cc +++ b/src/lib/dhcpsrv/mysql_lease_mgr.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2012-2014 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2012-2015 Internet Systems Consortium, Inc. ("ISC") // // Permission to use, copy, modify, and/or distribute this software for any // purpose with or without fee is hereby granted, provided that the above @@ -1270,9 +1270,17 @@ void MySqlLeaseMgr::convertToDatabaseTime(time_t cltt, uint32_t valid_lifetime, MYSQL_TIME& expire) { - // Calculate expiry time. - // @TODO: handle overflows - time_t expire_time = cltt + valid_lifetime; + // Calculate expiry time. Store it in the 64-bit value so as we can detect + // overflows. + int64_t expire_time_64 = static_cast(cltt) + + static_cast(valid_lifetime); + + // Prevent too large value. + if (expire_time_64 > LeaseMgr::MAX_DB_TIME) { + isc_throw(BadValue, "Time value is too large: " << expire_time_64); + } + + const time_t expire_time = static_cast(expire_time_64); // Convert to broken-out time struct tm expire_tm;