From 558a66fbe51a9a121dff671050a88592a14373e1 Mon Sep 17 00:00:00 2001 From: Dave Conway-Jones Date: Wed, 17 Jan 2018 09:35:47 +0000 Subject: [PATCH] restrict inject interval to less that 2^31 millisecs (596 hrs, 24 days) to stop overflow causing fast loop. (defaults to 0) to close #1485 --- nodes/core/core/20-inject.html | 4 +++- nodes/core/core/20-inject.js | 7 ++++++- nodes/core/locales/en-US/messages.json | 5 +++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/nodes/core/core/20-inject.html b/nodes/core/core/20-inject.html index 5577b78a4..4090fdbbd 100644 --- a/nodes/core/core/20-inject.html +++ b/nodes/core/core/20-inject.html @@ -170,6 +170,8 @@ The default payload is a timestamp of the current time in millisecs since Januar

By default, the node is triggered manually by clicking on its button within the editor. It can also be set to inject at regular intervals or according to a schedule.

It can also be configured to inject once each time the flows are started.

+

The maximum Interval that can be specified is about 596 hours / 24 days. However if you are looking at intervals +greater than one day you should consider using a scheduler node that can cope with power outages and restarts.

Note: The "Interval between times" and "at a specific time" options use the standard cron system. This means that 20 minutes will be at the next hour, 20 minutes past and 40 minutes past - not in 20 minutes time. If you want every 20 minutes from now - use the "interval" option.

@@ -185,7 +187,7 @@ If you want every 20 minutes from now - use the "interval" option.

topic: {value:""}, payload: {value:"", validate: RED.validators.typedInput("payloadType")}, payloadType: {value:"date"}, - repeat: {value:"", validate:function(v) { return ((v === "") || (RED.validators.number(v) && (v >= 0))) }}, + repeat: {value:"", validate:function(v) { return ((v === "") || (RED.validators.number(v) && (v >= 0) && (v <= 2147483))) }}, crontab: {value:""}, once: {value:false}, onceDelay: {value:0.1} diff --git a/nodes/core/core/20-inject.js b/nodes/core/core/20-inject.js index a5099769b..9e6eb62a8 100644 --- a/nodes/core/core/20-inject.js +++ b/nodes/core/core/20-inject.js @@ -27,9 +27,14 @@ module.exports = function(RED) { this.crontab = n.crontab; this.once = n.once; this.onceDelay = (n.onceDelay || 0.1) * 1000; - var node = this; this.interval_id = null; this.cronjob = null; + var node = this; + + if (node.repeat > 2147483) { + node.error(RED._("inject.errors.toolong", this)); + delete node.repeat; + } node.repeaterSetup = function () { if (this.repeat && !isNaN(this.repeat) && this.repeat > 0) { diff --git a/nodes/core/locales/en-US/messages.json b/nodes/core/locales/en-US/messages.json index 53cc00d11..c9d93f75e 100644 --- a/nodes/core/locales/en-US/messages.json +++ b/nodes/core/locales/en-US/messages.json @@ -61,10 +61,11 @@ "on": "on", "onstart": "Inject once after", "onceDelay": "seconds, then", - "tip": "Note: \"interval between times\" and \"at a specific time\" will use cron.
See info box for details.", + "tip": "Note: \"interval between times\" and \"at a specific time\" will use cron.
\"interval\" should be less than 596 hours.
See info box for details.", "success": "Successfully injected: __label__", "errors": { - "failed": "inject failed, see log for details" + "failed": "inject failed, see log for details", + "toolong": "Interval too large" } }, "catch": {