From 2215451b39d5660edd207c119c5366eb88d229ba Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Sun, 30 Oct 2016 18:04:42 +0100 Subject: [PATCH] BNetworkCookie: fix overflow in date computation. Fix one of the two failing tests from the cookie testsuite. --- src/kits/network/libnetapi/NetworkCookie.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/kits/network/libnetapi/NetworkCookie.cpp b/src/kits/network/libnetapi/NetworkCookie.cpp index e7cc37fcb6..23dc702ecd 100644 --- a/src/kits/network/libnetapi/NetworkCookie.cpp +++ b/src/kits/network/libnetapi/NetworkCookie.cpp @@ -279,7 +279,14 @@ BNetworkCookie& BNetworkCookie::SetMaxAge(int32 maxAge) { BDateTime expiration = BDateTime::CurrentDateTime(B_LOCAL_TIME); - expiration.SetTime_t(expiration.Time_t() + maxAge); + + // Compute the expiration date (watch out for overflows) + int64_t date = expiration.Time_t(); + date += (int64_t)maxAge; + if (date > INT_MAX) + date = INT_MAX; + + expiration.SetTime_t(date); return SetExpirationDate(expiration); }