From f38cd3c70bf5379cf81c75accf2b4d2301137a7d Mon Sep 17 00:00:00 2001 From: Mykhailo Bykhovtsev Date: Sun, 24 Mar 2019 04:21:04 -0700 Subject: [PATCH] Timers sanity checks Port from TG. (#6125) This adds timers sanity checks with stack tracing of where it was called. Check are: If timer had no callback(crashes timer) If timer was called with negative wait time. Converts time to 0 and gives call stack. If timer was called on deleted or about to be deleted object. Still runs, but gives call stack If timer had infinite or more wait time. Crashes timer Adds sanity check to beams for timer wait time. --- code/controllers/subsystems/timer.dm | 11 +++++++- code/datums/beam.dm | 3 ++ html/changelogs/Sindorman-timers.yml | 42 ++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 html/changelogs/Sindorman-timers.yml diff --git a/code/controllers/subsystems/timer.dm b/code/controllers/subsystems/timer.dm index 37bc406905d..d973de097a6 100644 --- a/code/controllers/subsystems/timer.dm +++ b/code/controllers/subsystems/timer.dm @@ -359,10 +359,19 @@ var/datum/controller/subsystem/timer/SStimer /proc/addtimer(datum/callback/callback, wait, flags) if (!callback) - return + CRASH("addtimer called without a callback") + + if (wait < 0) + crash_with("addtimer called with a negative wait. Converting to 0") + + if (callback.object != GLOBAL_PROC && QDELETED(callback.object) && !QDESTROYING(callback.object)) + crash_with("addtimer called with a callback assigned to a qdeleted object. In the future such timers will not be supported and may refuse to run or run with a 0 wait") wait = max(wait, 0) + if(wait >= INFINITY) + CRASH("Attempted to create timer with INFINITY delay") + var/hash if (flags & TIMER_UNIQUE) diff --git a/code/datums/beam.dm b/code/datums/beam.dm index a3e3c11c421..12774f86e7a 100644 --- a/code/datums/beam.dm +++ b/code/datums/beam.dm @@ -149,6 +149,9 @@ return ..() /atom/proc/Beam(atom/BeamTarget,icon_state="b_beam",icon='icons/effects/beam.dmi',time=50, maxdistance=10,beam_type=/obj/effect/ebeam,beam_sleep_time = 3) + if(time >= INFINITY) + crash_with("Tried to create beam with infinite time!") + return null var/datum/beam/newbeam = new(src,BeamTarget,icon,icon_state,time,maxdistance,beam_type,beam_sleep_time) INVOKE_ASYNC(newbeam, /datum/beam/.proc/Start) return newbeam diff --git a/html/changelogs/Sindorman-timers.yml b/html/changelogs/Sindorman-timers.yml new file mode 100644 index 00000000000..7202573bbf1 --- /dev/null +++ b/html/changelogs/Sindorman-timers.yml @@ -0,0 +1,42 @@ +################################ +# Example Changelog File +# +# Note: This file, and files beginning with ".", and files that don't end in ".yml" will not be read. If you change this file, you will look really dumb. +# +# Your changelog will be merged with a master changelog. (New stuff added only, and only on the date entry for the day it was merged.) +# When it is, any changes listed below will disappear. +# +# Valid Prefixes: +# bugfix +# wip (For works in progress) +# tweak +# soundadd +# sounddel +# rscadd (general adding of nice things) +# rscdel (general deleting of nice things) +# imageadd +# imagedel +# maptweak +# spellcheck (typo fixes) +# experiment +# balance +# admin +# backend +# security +# refactor +################################# + +# Your name. +author: PoZe + +# Optional: Remove this file after generating master changelog. Useful for PR changelogs that won't get used again. +delete-after: True + +# Any changes you've made. See valid prefix list above. +# INDENT WITH TWO SPACES. NOT TABS. SPACES. +# SCREW THIS UP AND IT WON'T WORK. +# Also, all entries are changed into a single [] after a master changelog generation. Just remove the brackets when you add new entries. +# Please surround your changes in double quotes ("), as certain characters otherwise screws up compiling. The quotes will not show up in the changelog. +changes: + - backend: "Timers now have sanity checks, if wait time is negative or infinite. Or if there is no callback or if object is about to be deleted or already deleted. Gives call stack for negative wait time and deleted object. Crashes if wait time is infinite." + - backend: "Beams now have sanity check if it was trying to call timer with infinite wait time."