diff -u unity-5.18.0/debian/changelog unity-5.18.0/debian/changelog --- unity-5.18.0/debian/changelog +++ unity-5.18.0/debian/changelog @@ -1,3 +1,11 @@ +unity (5.18.0-0ubuntu2) precise; urgency=low + + [ Brandon Schaefer ] + * Change TimeUtil to use int64, so the buffer wont overflow within + our lifetimes. (LP: #806248) + + -- Chris J Arges Tue, 08 Jan 2013 17:32:10 -0600 + unity (5.18.0-0ubuntu1) precise-proposed; urgency=low * New upstream release. only in patch2: unchanged: --- unity-5.18.0.orig/tests/CMakeLists.txt +++ unity-5.18.0/tests/CMakeLists.txt @@ -143,6 +143,7 @@ test_introspection.cpp test_main_xless.cpp test_grabhandle.cpp + test_time_util.cpp test_unityshell_private.cpp test_showdesktop_handler.cpp test_hud_private.cpp only in patch2: unchanged: --- unity-5.18.0.orig/tests/test_time_util.cpp +++ unity-5.18.0/tests/test_time_util.cpp @@ -0,0 +1,38 @@ +// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- +/* +* Copyright (C) 2012 Canonical Ltd +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 3 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* +* Authored by: Brandon Schaefer +* +*/ + + +#include +#include +#include "TimeUtil.h" + +using namespace testing; + +TEST(TestTimeUtil, Testin32BufferOverflow) +{ + struct timespec start, end; + unity::TimeUtil::SetTimeStruct(&start); + unity::TimeUtil::SetTimeStruct(&end); + + end.tv_sec = start.tv_sec + INT32_MAX; + + EXPECT_GT(unity::TimeUtil::TimeDelta(&end, &start), 0); +} + only in patch2: unchanged: --- unity-5.18.0.orig/plugins/unityshell/src/TimeUtil.h +++ unity-5.18.0/plugins/unityshell/src/TimeUtil.h @@ -19,29 +19,34 @@ */ #include +#include + +typedef int64_t DeltaTime; namespace unity { class TimeUtil { public: - static int TimeDelta (struct timespec const* x, struct timespec const* y) + static DeltaTime TimeDelta (struct timespec const* x, struct timespec const* y) { - return ((x->tv_sec - y->tv_sec) * 1000) + ((x->tv_nsec - y->tv_nsec) / 1000000); + DeltaTime d_sec = (x->tv_sec - y->tv_sec); + DeltaTime d_nsec = (x->tv_nsec - y->tv_nsec); + return (d_sec * 1000) + (d_nsec / 1000000); } - static void SetTimeStruct(struct timespec* timer, struct timespec* sister = 0, int sister_relation = 0) + static void SetTimeStruct(struct timespec* timer, struct timespec* sister = 0, DeltaTime sister_relation = 0) { struct timespec current; clock_gettime(CLOCK_MONOTONIC, ¤t); if (sister) { - int diff = TimeDelta(¤t, sister); + DeltaTime diff = TimeDelta(¤t, sister); if (diff < sister_relation) { - int remove = sister_relation - diff; + DeltaTime remove = sister_relation - diff; SetTimeBack(¤t, remove); } } @@ -50,7 +55,7 @@ timer->tv_nsec = current.tv_nsec; } - static void SetTimeBack(struct timespec* timeref, int remove) + static void SetTimeBack(struct timespec* timeref, DeltaTime remove) { timeref->tv_sec -= remove / 1000; remove = remove % 1000; only in patch2: unchanged: --- unity-5.18.0.orig/plugins/unityshell/src/Launcher.cpp +++ unity-5.18.0/plugins/unityshell/src/Launcher.cpp @@ -646,13 +646,13 @@ if (icon->GetQuirk(AbstractLauncherIcon::QUIRK_VISIBLE)) { struct timespec icon_visible_time = icon->GetQuirkTime(AbstractLauncherIcon::QUIRK_VISIBLE); - int enter_ms = unity::TimeUtil::TimeDelta(¤t, &icon_visible_time); + DeltaTime enter_ms = unity::TimeUtil::TimeDelta(¤t, &icon_visible_time); return CLAMP((float) enter_ms / (float) ANIM_DURATION_SHORT, 0.0f, 1.0f); } else { struct timespec icon_hide_time = icon->GetQuirkTime(AbstractLauncherIcon::QUIRK_VISIBLE); - int hide_ms = unity::TimeUtil::TimeDelta(¤t, &icon_hide_time); + DeltaTime hide_ms = unity::TimeUtil::TimeDelta(¤t, &icon_hide_time); return 1.0f - CLAMP((float) hide_ms / (float) ANIM_DURATION_SHORT, 0.0f, 1.0f); } } @@ -685,7 +685,7 @@ float Launcher::IconPresentProgress(AbstractLauncherIcon::Ptr icon, struct timespec const& current) const { struct timespec icon_present_time = icon->GetQuirkTime(AbstractLauncherIcon::QUIRK_PRESENTED); - int ms = unity::TimeUtil::TimeDelta(¤t, &icon_present_time); + DeltaTime ms = unity::TimeUtil::TimeDelta(¤t, &icon_present_time); float result = CLAMP((float) ms / (float) ANIM_DURATION, 0.0f, 1.0f); if (icon->GetQuirk(AbstractLauncherIcon::QUIRK_PRESENTED)) @@ -697,7 +697,7 @@ float Launcher::IconUrgentProgress(AbstractLauncherIcon::Ptr icon, struct timespec const& current) const { struct timespec urgent_time = icon->GetQuirkTime(AbstractLauncherIcon::QUIRK_URGENT); - int urgent_ms = unity::TimeUtil::TimeDelta(¤t, &urgent_time); + DeltaTime urgent_ms = unity::TimeUtil::TimeDelta(¤t, &urgent_time); float result; if (options()->urgent_animation() == URGENT_ANIMATION_WIGGLE) @@ -714,7 +714,7 @@ float Launcher::IconDropDimValue(AbstractLauncherIcon::Ptr icon, struct timespec const& current) const { struct timespec dim_time = icon->GetQuirkTime(AbstractLauncherIcon::QUIRK_DROP_DIM); - int dim_ms = unity::TimeUtil::TimeDelta(¤t, &dim_time); + DeltaTime dim_ms = unity::TimeUtil::TimeDelta(¤t, &dim_time); float result = CLAMP((float) dim_ms / (float) ANIM_DURATION, 0.0f, 1.0f); if (icon->GetQuirk(AbstractLauncherIcon::QUIRK_DROP_DIM)) @@ -729,7 +729,7 @@ return 1.0f; struct timespec dim_time = icon->GetQuirkTime(AbstractLauncherIcon::QUIRK_DESAT); - int ms = unity::TimeUtil::TimeDelta(¤t, &dim_time); + DeltaTime ms = unity::TimeUtil::TimeDelta(¤t, &dim_time); float result = CLAMP((float) ms / (float) ANIM_DURATION_SHORT_SHORT, 0.0f, 1.0f); if (icon->GetQuirk(AbstractLauncherIcon::QUIRK_DESAT)) @@ -741,14 +741,14 @@ float Launcher::IconShimmerProgress(AbstractLauncherIcon::Ptr icon, struct timespec const& current) const { struct timespec shimmer_time = icon->GetQuirkTime(AbstractLauncherIcon::QUIRK_SHIMMER); - int shimmer_ms = unity::TimeUtil::TimeDelta(¤t, &shimmer_time); + DeltaTime shimmer_ms = unity::TimeUtil::TimeDelta(¤t, &shimmer_time); return CLAMP((float) shimmer_ms / (float) ANIM_DURATION_LONG, 0.0f, 1.0f); } float Launcher::IconCenterTransitionProgress(AbstractLauncherIcon::Ptr icon, struct timespec const& current) const { struct timespec save_time = icon->GetQuirkTime(AbstractLauncherIcon::QUIRK_CENTER_SAVED); - int save_ms = unity::TimeUtil::TimeDelta(¤t, &save_time); + DeltaTime save_ms = unity::TimeUtil::TimeDelta(¤t, &save_time); return CLAMP((float) save_ms / (float) ANIM_DURATION, 0.0f, 1.0f); } @@ -764,7 +764,7 @@ float Launcher::IconPulseOnceValue(AbstractLauncherIcon::Ptr icon, struct timespec const ¤t) const { struct timespec pulse_time = icon->GetQuirkTime(AbstractLauncherIcon::QUIRK_PULSE_ONCE); - int pulse_ms = unity::TimeUtil::TimeDelta(¤t, &pulse_time); + DeltaTime pulse_ms = unity::TimeUtil::TimeDelta(¤t, &pulse_time); double pulse_progress = (double) CLAMP((float) pulse_ms / (ANIM_DURATION_LONG * PULSE_BLINK_LAMBDA * 2), 0.0f, 1.0f); if (pulse_progress == 1.0f) @@ -785,7 +785,7 @@ float Launcher::IconStartingBlinkValue(AbstractLauncherIcon::Ptr icon, struct timespec const& current) const { struct timespec starting_time = icon->GetQuirkTime(AbstractLauncherIcon::QUIRK_STARTING); - int starting_ms = unity::TimeUtil::TimeDelta(¤t, &starting_time); + DeltaTime starting_ms = unity::TimeUtil::TimeDelta(¤t, &starting_time); double starting_progress = (double) CLAMP((float) starting_ms / (float)(ANIM_DURATION_LONG * STARTING_BLINK_LAMBDA), 0.0f, 1.0f); double val = IsBackLightModeToggles() ? 3.0f : 4.0f; return 0.5f + (float)(std::cos(M_PI * val * starting_progress)) * 0.5f; @@ -794,7 +794,7 @@ float Launcher::IconStartingPulseValue(AbstractLauncherIcon::Ptr icon, struct timespec const& current) const { struct timespec starting_time = icon->GetQuirkTime(AbstractLauncherIcon::QUIRK_STARTING); - int starting_ms = unity::TimeUtil::TimeDelta(¤t, &starting_time); + DeltaTime starting_ms = unity::TimeUtil::TimeDelta(¤t, &starting_time); double starting_progress = (double) CLAMP((float) starting_ms / (float)(ANIM_DURATION_LONG * MAX_STARTING_BLINKS * STARTING_BLINK_LAMBDA * 2), 0.0f, 1.0f); if (starting_progress == 1.0f && !icon->GetQuirk(AbstractLauncherIcon::QUIRK_RUNNING)) @@ -811,7 +811,7 @@ float result = 0.0f; struct timespec running_time = icon->GetQuirkTime(AbstractLauncherIcon::QUIRK_RUNNING); - int running_ms = unity::TimeUtil::TimeDelta(¤t, &running_time); + DeltaTime running_ms = unity::TimeUtil::TimeDelta(¤t, &running_time); float running_progress = CLAMP((float) running_ms / (float) ANIM_DURATION_SHORT, 0.0f, 1.0f); if (!icon->GetQuirk(AbstractLauncherIcon::QUIRK_RUNNING)) @@ -876,7 +876,7 @@ float Launcher::IconProgressBias(AbstractLauncherIcon::Ptr icon, struct timespec const& current) const { struct timespec icon_progress_time = icon->GetQuirkTime(AbstractLauncherIcon::QUIRK_PROGRESS); - int ms = unity::TimeUtil::TimeDelta(¤t, &icon_progress_time); + DeltaTime ms = unity::TimeUtil::TimeDelta(¤t, &icon_progress_time); float result = CLAMP((float) ms / (float) ANIM_DURATION, 0.0f, 1.0f); if (icon->GetQuirk(AbstractLauncherIcon::QUIRK_PROGRESS)) only in patch2: unchanged: --- unity-5.18.0.orig/plugins/unityshell/src/SwitcherView.cpp +++ unity-5.18.0/plugins/unityshell/src/SwitcherView.cpp @@ -251,7 +251,7 @@ { std::vector xids = model_->DetailXids (); - int ms_since_change = TimeUtil::TimeDelta(¤t, &save_time_); + DeltaTime ms_since_change = TimeUtil::TimeDelta(¤t, &save_time_); float progress = MIN (1.0f, (float) ms_since_change / (float) animation_length()); for (Window window : xids) @@ -508,7 +508,7 @@ ++i; } - int ms_since_change = TimeUtil::TimeDelta(¤t, &save_time_); + DeltaTime ms_since_change = TimeUtil::TimeDelta(¤t, &save_time_); if (saved_args_.size () == results.size () && ms_since_change < animation_length) { float progress = (float) ms_since_change / (float) animation_length(); @@ -630,7 +630,7 @@ text_view_->SetBaseY(last_background_.y + last_background_.height - 45); text_view_->Draw(GfxContext, force_draw); - int ms_since_change = TimeUtil::TimeDelta(¤t_, &save_time_); + DeltaTime ms_since_change = TimeUtil::TimeDelta(¤t_, &save_time_); if (ms_since_change < animation_length && redraw_handle_ == 0) redraw_handle_ = g_idle_add_full (G_PRIORITY_DEFAULT, &SwitcherView::OnDrawTimeout, this, NULL); only in patch2: unchanged: --- unity-5.18.0.orig/plugins/unityshell/src/ElapsedTimeMonitor.cpp +++ unity-5.18.0/plugins/unityshell/src/ElapsedTimeMonitor.cpp @@ -39,7 +39,7 @@ { struct timespec current; clock_gettime(CLOCK_MONOTONIC, ¤t); - int diff = TimeUtil::TimeDelta(¤t, &_start); + DeltaTime diff = TimeUtil::TimeDelta(¤t, &_start); variant::BuilderWrapper(builder) .add("elapsed-time", diff);