From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.20; helo=mga02.intel.com; envelope-from=jiaxin.wu@intel.com; receiver=edk2-devel@lists.01.org Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 491C521B02822 for ; Mon, 15 Oct 2018 22:36:15 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 15 Oct 2018 22:36:14 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,387,1534834800"; d="scan'208";a="99547164" Received: from jiaxinwu-mobl.ccr.corp.intel.com ([10.239.192.155]) by fmsmga001.fm.intel.com with ESMTP; 15 Oct 2018 22:36:13 -0700 From: Jiaxin Wu To: edk2-devel@lists.01.org Cc: Fu Siyuan , Ye Ting , Wu Jiaxin Date: Tue, 16 Oct 2018 13:36:09 +0800 Message-Id: <20181016053609.704-1-Jiaxin.wu@intel.com> X-Mailer: git-send-email 2.17.1.windows.2 Subject: [Patch] NetworkPkg: Correct the time stamp and fix the integer overflow issue. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 16 Oct 2018 05:36:15 -0000 Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=883. Cc: Fu Siyuan Cc: Ye Ting Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Wu Jiaxin --- NetworkPkg/Dhcp6Dxe/Dhcp6Utility.c | 18 +++++++++--------- NetworkPkg/UefiPxeBcDxe/PxeBcSupport.c | 16 ++++++++-------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/NetworkPkg/Dhcp6Dxe/Dhcp6Utility.c b/NetworkPkg/Dhcp6Dxe/Dhcp6Utility.c index 10a99a00d4..9c7459c332 100644 --- a/NetworkPkg/Dhcp6Dxe/Dhcp6Utility.c +++ b/NetworkPkg/Dhcp6Dxe/Dhcp6Utility.c @@ -121,11 +121,11 @@ Dhcp6GenerateClientId ( // Generate a time stamp of the seconds from 2000/1/1, assume 30day/month. // gRT->GetTime (&Time, NULL); Stamp = (UINT32) ( - (((((Time.Year - 2000) * 360 + (Time.Month - 1)) * 30 + (Time.Day - 1)) * 24 + Time.Hour) * 60 + Time.Minute) * + ((((UINT32)(Time.Year - 2000) * 360 + (Time.Month - 1) * 30 + (Time.Day - 1)) * 24 + Time.Hour) * 60 + Time.Minute) * 60 + Time.Second ); // @@ -879,18 +879,18 @@ SetElapsedTime ( // // Generate a time stamp of the centiseconds from 2000/1/1, assume 30day/month. // gRT->GetTime (&Time, NULL); - CurrentStamp = (UINT64) - ( - ((((((Time.Year - 2000) * 360 + - (Time.Month - 1)) * 30 + - (Time.Day - 1)) * 24 + Time.Hour) * 60 + - Time.Minute) * 60 + Time.Second) * 100 - + DivU64x32(Time.Nanosecond, 10000000) - ); + CurrentStamp = MultU64x32 ( + ((((UINT32)(Time.Year - 2000) * 360 + (Time.Month - 1) * 30 + (Time.Day - 1)) * 24 + Time.Hour) * 60 + Time.Minute) * 60 + Time.Second, + 100 + ) + + DivU64x32( + Time.Nanosecond, + 10000000 + ); // // Sentinel value of 0 means that this is the first DHCP packet that we are // sending and that we need to initialize the value. First DHCP message // gets 0 elapsed-time. Otherwise, calculate based on StartTime. diff --git a/NetworkPkg/UefiPxeBcDxe/PxeBcSupport.c b/NetworkPkg/UefiPxeBcDxe/PxeBcSupport.c index 60509fc9e6..7ab09e0367 100644 --- a/NetworkPkg/UefiPxeBcDxe/PxeBcSupport.c +++ b/NetworkPkg/UefiPxeBcDxe/PxeBcSupport.c @@ -1508,18 +1508,18 @@ CalcElapsedTime ( // // Generate a time stamp of the centiseconds from 1900/1/1, assume 30day/month. // ZeroMem (&Time, sizeof (EFI_TIME)); gRT->GetTime (&Time, NULL); - CurrentStamp = (UINT64) - ( - ((((((Time.Year - 1900) * 360 + - (Time.Month - 1)) * 30 + - (Time.Day - 1)) * 24 + Time.Hour) * 60 + - Time.Minute) * 60 + Time.Second) * 100 - + DivU64x32(Time.Nanosecond, 10000000) - ); + CurrentStamp = MultU64x32 ( + ((((UINT32)(Time.Year - 1900) * 360 + (Time.Month - 1) * 30 + (Time.Day - 1)) * 24 + Time.Hour) * 60 + Time.Minute) * 60 + Time.Second, + 100 + ) + + DivU64x32 ( + Time.Nanosecond, + 10000000 + ); // // Sentinel value of 0 means that this is the first DHCP packet that we are // sending and that we need to initialize the value. First DHCP Solicit // gets 0 elapsed-time. Otherwise, calculate based on StartTime. -- 2.17.1.windows.2