Merge lp:~timo-jyrinki/unity/ubuntu.lp806248-fix-int32-buffer-overflow-5.0 into lp:~ubuntu-desktop/unity/precise

Proposed by Timo Jyrinki
Status: Merged
Merged at revision: 712
Proposed branch: lp:~timo-jyrinki/unity/ubuntu.lp806248-fix-int32-buffer-overflow-5.0
Merge into: lp:~ubuntu-desktop/unity/precise
Diff against target: 285 lines (+75/-23)
7 files modified
debian/changelog (+8/-0)
plugins/unityshell/src/ElapsedTimeMonitor.cpp (+1/-1)
plugins/unityshell/src/Launcher.cpp (+13/-13)
plugins/unityshell/src/SwitcherView.cpp (+3/-3)
plugins/unityshell/src/TimeUtil.h (+11/-6)
tests/CMakeLists.txt (+1/-0)
tests/test_time_util.cpp (+38/-0)
To merge this branch: bzr merge lp:~timo-jyrinki/unity/ubuntu.lp806248-fix-int32-buffer-overflow-5.0
Reviewer Review Type Date Requested Status
Ubuntu Desktop Pending
Review via email: mp+145178@code.launchpad.net

Commit message

Change TimeUtil to use int64, so the buffer wont overflow within our lifetimes. (LP: #806248)

Description of the change

Change TimeUtil to use int64, so the buffer wont overflow within our lifetimes. (LP: #806248)

bzr cherry-picked this one for Chris, identical to his debdiff. The same patch is already published in quantal-updates.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/changelog'
2--- debian/changelog 2012-11-19 11:27:26 +0000
3+++ debian/changelog 2013-01-28 13:04:31 +0000
4@@ -1,3 +1,11 @@
5+unity (5.18.0-0ubuntu2) precise; urgency=low
6+
7+ [ Brandon Schaefer ]
8+ * Change TimeUtil to use int64, so the buffer wont overflow within
9+ our lifetimes. (LP: #806248)
10+
11+ -- Chris J Arges <chris.j.arges@canonical.com> Tue, 08 Jan 2013 17:32:10 -0600
12+
13 unity (5.18.0-0ubuntu1) precise-proposed; urgency=low
14
15 * New upstream release.
16
17=== modified file 'plugins/unityshell/src/ElapsedTimeMonitor.cpp'
18--- plugins/unityshell/src/ElapsedTimeMonitor.cpp 2012-03-14 06:24:18 +0000
19+++ plugins/unityshell/src/ElapsedTimeMonitor.cpp 2013-01-28 13:04:31 +0000
20@@ -39,7 +39,7 @@
21 {
22 struct timespec current;
23 clock_gettime(CLOCK_MONOTONIC, &current);
24- int diff = TimeUtil::TimeDelta(&current, &_start);
25+ DeltaTime diff = TimeUtil::TimeDelta(&current, &_start);
26
27 variant::BuilderWrapper(builder)
28 .add("elapsed-time", diff);
29
30=== modified file 'plugins/unityshell/src/Launcher.cpp'
31--- plugins/unityshell/src/Launcher.cpp 2012-11-12 12:20:38 +0000
32+++ plugins/unityshell/src/Launcher.cpp 2013-01-28 13:04:31 +0000
33@@ -646,13 +646,13 @@
34 if (icon->GetQuirk(AbstractLauncherIcon::QUIRK_VISIBLE))
35 {
36 struct timespec icon_visible_time = icon->GetQuirkTime(AbstractLauncherIcon::QUIRK_VISIBLE);
37- int enter_ms = unity::TimeUtil::TimeDelta(&current, &icon_visible_time);
38+ DeltaTime enter_ms = unity::TimeUtil::TimeDelta(&current, &icon_visible_time);
39 return CLAMP((float) enter_ms / (float) ANIM_DURATION_SHORT, 0.0f, 1.0f);
40 }
41 else
42 {
43 struct timespec icon_hide_time = icon->GetQuirkTime(AbstractLauncherIcon::QUIRK_VISIBLE);
44- int hide_ms = unity::TimeUtil::TimeDelta(&current, &icon_hide_time);
45+ DeltaTime hide_ms = unity::TimeUtil::TimeDelta(&current, &icon_hide_time);
46 return 1.0f - CLAMP((float) hide_ms / (float) ANIM_DURATION_SHORT, 0.0f, 1.0f);
47 }
48 }
49@@ -685,7 +685,7 @@
50 float Launcher::IconPresentProgress(AbstractLauncherIcon::Ptr icon, struct timespec const& current) const
51 {
52 struct timespec icon_present_time = icon->GetQuirkTime(AbstractLauncherIcon::QUIRK_PRESENTED);
53- int ms = unity::TimeUtil::TimeDelta(&current, &icon_present_time);
54+ DeltaTime ms = unity::TimeUtil::TimeDelta(&current, &icon_present_time);
55 float result = CLAMP((float) ms / (float) ANIM_DURATION, 0.0f, 1.0f);
56
57 if (icon->GetQuirk(AbstractLauncherIcon::QUIRK_PRESENTED))
58@@ -697,7 +697,7 @@
59 float Launcher::IconUrgentProgress(AbstractLauncherIcon::Ptr icon, struct timespec const& current) const
60 {
61 struct timespec urgent_time = icon->GetQuirkTime(AbstractLauncherIcon::QUIRK_URGENT);
62- int urgent_ms = unity::TimeUtil::TimeDelta(&current, &urgent_time);
63+ DeltaTime urgent_ms = unity::TimeUtil::TimeDelta(&current, &urgent_time);
64 float result;
65
66 if (options()->urgent_animation() == URGENT_ANIMATION_WIGGLE)
67@@ -714,7 +714,7 @@
68 float Launcher::IconDropDimValue(AbstractLauncherIcon::Ptr icon, struct timespec const& current) const
69 {
70 struct timespec dim_time = icon->GetQuirkTime(AbstractLauncherIcon::QUIRK_DROP_DIM);
71- int dim_ms = unity::TimeUtil::TimeDelta(&current, &dim_time);
72+ DeltaTime dim_ms = unity::TimeUtil::TimeDelta(&current, &dim_time);
73 float result = CLAMP((float) dim_ms / (float) ANIM_DURATION, 0.0f, 1.0f);
74
75 if (icon->GetQuirk(AbstractLauncherIcon::QUIRK_DROP_DIM))
76@@ -729,7 +729,7 @@
77 return 1.0f;
78
79 struct timespec dim_time = icon->GetQuirkTime(AbstractLauncherIcon::QUIRK_DESAT);
80- int ms = unity::TimeUtil::TimeDelta(&current, &dim_time);
81+ DeltaTime ms = unity::TimeUtil::TimeDelta(&current, &dim_time);
82 float result = CLAMP((float) ms / (float) ANIM_DURATION_SHORT_SHORT, 0.0f, 1.0f);
83
84 if (icon->GetQuirk(AbstractLauncherIcon::QUIRK_DESAT))
85@@ -741,14 +741,14 @@
86 float Launcher::IconShimmerProgress(AbstractLauncherIcon::Ptr icon, struct timespec const& current) const
87 {
88 struct timespec shimmer_time = icon->GetQuirkTime(AbstractLauncherIcon::QUIRK_SHIMMER);
89- int shimmer_ms = unity::TimeUtil::TimeDelta(&current, &shimmer_time);
90+ DeltaTime shimmer_ms = unity::TimeUtil::TimeDelta(&current, &shimmer_time);
91 return CLAMP((float) shimmer_ms / (float) ANIM_DURATION_LONG, 0.0f, 1.0f);
92 }
93
94 float Launcher::IconCenterTransitionProgress(AbstractLauncherIcon::Ptr icon, struct timespec const& current) const
95 {
96 struct timespec save_time = icon->GetQuirkTime(AbstractLauncherIcon::QUIRK_CENTER_SAVED);
97- int save_ms = unity::TimeUtil::TimeDelta(&current, &save_time);
98+ DeltaTime save_ms = unity::TimeUtil::TimeDelta(&current, &save_time);
99 return CLAMP((float) save_ms / (float) ANIM_DURATION, 0.0f, 1.0f);
100 }
101
102@@ -764,7 +764,7 @@
103 float Launcher::IconPulseOnceValue(AbstractLauncherIcon::Ptr icon, struct timespec const &current) const
104 {
105 struct timespec pulse_time = icon->GetQuirkTime(AbstractLauncherIcon::QUIRK_PULSE_ONCE);
106- int pulse_ms = unity::TimeUtil::TimeDelta(&current, &pulse_time);
107+ DeltaTime pulse_ms = unity::TimeUtil::TimeDelta(&current, &pulse_time);
108 double pulse_progress = (double) CLAMP((float) pulse_ms / (ANIM_DURATION_LONG * PULSE_BLINK_LAMBDA * 2), 0.0f, 1.0f);
109
110 if (pulse_progress == 1.0f)
111@@ -785,7 +785,7 @@
112 float Launcher::IconStartingBlinkValue(AbstractLauncherIcon::Ptr icon, struct timespec const& current) const
113 {
114 struct timespec starting_time = icon->GetQuirkTime(AbstractLauncherIcon::QUIRK_STARTING);
115- int starting_ms = unity::TimeUtil::TimeDelta(&current, &starting_time);
116+ DeltaTime starting_ms = unity::TimeUtil::TimeDelta(&current, &starting_time);
117 double starting_progress = (double) CLAMP((float) starting_ms / (float)(ANIM_DURATION_LONG * STARTING_BLINK_LAMBDA), 0.0f, 1.0f);
118 double val = IsBackLightModeToggles() ? 3.0f : 4.0f;
119 return 0.5f + (float)(std::cos(M_PI * val * starting_progress)) * 0.5f;
120@@ -794,7 +794,7 @@
121 float Launcher::IconStartingPulseValue(AbstractLauncherIcon::Ptr icon, struct timespec const& current) const
122 {
123 struct timespec starting_time = icon->GetQuirkTime(AbstractLauncherIcon::QUIRK_STARTING);
124- int starting_ms = unity::TimeUtil::TimeDelta(&current, &starting_time);
125+ DeltaTime starting_ms = unity::TimeUtil::TimeDelta(&current, &starting_time);
126 double starting_progress = (double) CLAMP((float) starting_ms / (float)(ANIM_DURATION_LONG * MAX_STARTING_BLINKS * STARTING_BLINK_LAMBDA * 2), 0.0f, 1.0f);
127
128 if (starting_progress == 1.0f && !icon->GetQuirk(AbstractLauncherIcon::QUIRK_RUNNING))
129@@ -811,7 +811,7 @@
130 float result = 0.0f;
131
132 struct timespec running_time = icon->GetQuirkTime(AbstractLauncherIcon::QUIRK_RUNNING);
133- int running_ms = unity::TimeUtil::TimeDelta(&current, &running_time);
134+ DeltaTime running_ms = unity::TimeUtil::TimeDelta(&current, &running_time);
135 float running_progress = CLAMP((float) running_ms / (float) ANIM_DURATION_SHORT, 0.0f, 1.0f);
136
137 if (!icon->GetQuirk(AbstractLauncherIcon::QUIRK_RUNNING))
138@@ -876,7 +876,7 @@
139 float Launcher::IconProgressBias(AbstractLauncherIcon::Ptr icon, struct timespec const& current) const
140 {
141 struct timespec icon_progress_time = icon->GetQuirkTime(AbstractLauncherIcon::QUIRK_PROGRESS);
142- int ms = unity::TimeUtil::TimeDelta(&current, &icon_progress_time);
143+ DeltaTime ms = unity::TimeUtil::TimeDelta(&current, &icon_progress_time);
144 float result = CLAMP((float) ms / (float) ANIM_DURATION, 0.0f, 1.0f);
145
146 if (icon->GetQuirk(AbstractLauncherIcon::QUIRK_PROGRESS))
147
148=== modified file 'plugins/unityshell/src/SwitcherView.cpp'
149--- plugins/unityshell/src/SwitcherView.cpp 2012-03-23 12:26:38 +0000
150+++ plugins/unityshell/src/SwitcherView.cpp 2013-01-28 13:04:31 +0000
151@@ -251,7 +251,7 @@
152 {
153 std::vector<Window> xids = model_->DetailXids ();
154
155- int ms_since_change = TimeUtil::TimeDelta(&current, &save_time_);
156+ DeltaTime ms_since_change = TimeUtil::TimeDelta(&current, &save_time_);
157 float progress = MIN (1.0f, (float) ms_since_change / (float) animation_length());
158
159 for (Window window : xids)
160@@ -508,7 +508,7 @@
161 ++i;
162 }
163
164- int ms_since_change = TimeUtil::TimeDelta(&current, &save_time_);
165+ DeltaTime ms_since_change = TimeUtil::TimeDelta(&current, &save_time_);
166 if (saved_args_.size () == results.size () && ms_since_change < animation_length)
167 {
168 float progress = (float) ms_since_change / (float) animation_length();
169@@ -630,7 +630,7 @@
170 text_view_->SetBaseY(last_background_.y + last_background_.height - 45);
171 text_view_->Draw(GfxContext, force_draw);
172
173- int ms_since_change = TimeUtil::TimeDelta(&current_, &save_time_);
174+ DeltaTime ms_since_change = TimeUtil::TimeDelta(&current_, &save_time_);
175
176 if (ms_since_change < animation_length && redraw_handle_ == 0)
177 redraw_handle_ = g_idle_add_full (G_PRIORITY_DEFAULT, &SwitcherView::OnDrawTimeout, this, NULL);
178
179=== modified file 'plugins/unityshell/src/TimeUtil.h'
180--- plugins/unityshell/src/TimeUtil.h 2012-03-14 06:24:18 +0000
181+++ plugins/unityshell/src/TimeUtil.h 2013-01-28 13:04:31 +0000
182@@ -19,29 +19,34 @@
183 */
184
185 #include <time.h>
186+#include <cstdint>
187+
188+typedef int64_t DeltaTime;
189
190 namespace unity {
191
192 class TimeUtil
193 {
194 public:
195- static int TimeDelta (struct timespec const* x, struct timespec const* y)
196+ static DeltaTime TimeDelta (struct timespec const* x, struct timespec const* y)
197 {
198- return ((x->tv_sec - y->tv_sec) * 1000) + ((x->tv_nsec - y->tv_nsec) / 1000000);
199+ DeltaTime d_sec = (x->tv_sec - y->tv_sec);
200+ DeltaTime d_nsec = (x->tv_nsec - y->tv_nsec);
201+ return (d_sec * 1000) + (d_nsec / 1000000);
202 }
203
204- static void SetTimeStruct(struct timespec* timer, struct timespec* sister = 0, int sister_relation = 0)
205+ static void SetTimeStruct(struct timespec* timer, struct timespec* sister = 0, DeltaTime sister_relation = 0)
206 {
207 struct timespec current;
208 clock_gettime(CLOCK_MONOTONIC, &current);
209
210 if (sister)
211 {
212- int diff = TimeDelta(&current, sister);
213+ DeltaTime diff = TimeDelta(&current, sister);
214
215 if (diff < sister_relation)
216 {
217- int remove = sister_relation - diff;
218+ DeltaTime remove = sister_relation - diff;
219 SetTimeBack(&current, remove);
220 }
221 }
222@@ -50,7 +55,7 @@
223 timer->tv_nsec = current.tv_nsec;
224 }
225
226- static void SetTimeBack(struct timespec* timeref, int remove)
227+ static void SetTimeBack(struct timespec* timeref, DeltaTime remove)
228 {
229 timeref->tv_sec -= remove / 1000;
230 remove = remove % 1000;
231
232=== modified file 'tests/CMakeLists.txt'
233--- tests/CMakeLists.txt 2012-11-12 12:20:38 +0000
234+++ tests/CMakeLists.txt 2013-01-28 13:04:31 +0000
235@@ -143,6 +143,7 @@
236 test_introspection.cpp
237 test_main_xless.cpp
238 test_grabhandle.cpp
239+ test_time_util.cpp
240 test_unityshell_private.cpp
241 test_showdesktop_handler.cpp
242 test_hud_private.cpp
243
244=== added file 'tests/test_time_util.cpp'
245--- tests/test_time_util.cpp 1970-01-01 00:00:00 +0000
246+++ tests/test_time_util.cpp 2013-01-28 13:04:31 +0000
247@@ -0,0 +1,38 @@
248+// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
249+/*
250+* Copyright (C) 2012 Canonical Ltd
251+*
252+* This program is free software: you can redistribute it and/or modify
253+* it under the terms of the GNU General Public License version 3 as
254+* published by the Free Software Foundation.
255+*
256+* This program is distributed in the hope that it will be useful,
257+* but WITHOUT ANY WARRANTY; without even the implied warranty of
258+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
259+* GNU General Public License for more details.
260+*
261+* You should have received a copy of the GNU General Public License
262+* along with this program. If not, see <http://www.gnu.org/licenses/>.
263+*
264+* Authored by: Brandon Schaefer <brandon.schaefer@canonical.com>
265+*
266+*/
267+
268+
269+#include <cinttypes>
270+#include <gtest/gtest.h>
271+#include "TimeUtil.h"
272+
273+using namespace testing;
274+
275+TEST(TestTimeUtil, Testin32BufferOverflow)
276+{
277+ struct timespec start, end;
278+ unity::TimeUtil::SetTimeStruct(&start);
279+ unity::TimeUtil::SetTimeStruct(&end);
280+
281+ end.tv_sec = start.tv_sec + INT32_MAX;
282+
283+ EXPECT_GT(unity::TimeUtil::TimeDelta(&end, &start), 0);
284+}
285+

Subscribers

People subscribed via source and target branches

to all changes: