Skip to content
Snippets Groups Projects
Commit 966e49ad authored by Tom French's avatar Tom French Committed by James Long
Browse files

fix: enforce proper length constraints on timestamp counter and node id

parent c66c316b
No related branches found
No related tags found
No related merge requests found
...@@ -75,6 +75,9 @@ var config = { ...@@ -75,6 +75,9 @@ var config = {
maxDrift: 5 * 60 * 1000 maxDrift: 5 * 60 * 1000
}; };
const MAX_COUNTER = parseInt('0xFFFF');
const MAX_NODE_LENGTH = 16;
/** /**
* timestamp instance class * timestamp instance class
*/ */
...@@ -191,7 +194,7 @@ Timestamp.send = function() { ...@@ -191,7 +194,7 @@ Timestamp.send = function() {
if (lNew - phys > config.maxDrift) { if (lNew - phys > config.maxDrift) {
throw new Timestamp.ClockDriftError(lNew, phys, config.maxDrift); throw new Timestamp.ClockDriftError(lNew, phys, config.maxDrift);
} }
if (cNew > 65535) { if (cNew > MAX_COUNTER) {
throw new Timestamp.OverflowError(); throw new Timestamp.OverflowError();
} }
...@@ -253,7 +256,7 @@ Timestamp.recv = function(msg) { ...@@ -253,7 +256,7 @@ Timestamp.recv = function(msg) {
if (lNew - phys > config.maxDrift) { if (lNew - phys > config.maxDrift) {
throw new Timestamp.ClockDriftError(); throw new Timestamp.ClockDriftError();
} }
if (cNew > 65535) { if (cNew > MAX_COUNTER) {
throw new Timestamp.OverflowError(); throw new Timestamp.OverflowError();
} }
...@@ -279,8 +282,16 @@ Timestamp.parse = function(timestamp) { ...@@ -279,8 +282,16 @@ Timestamp.parse = function(timestamp) {
var millis = Date.parse(parts.slice(0, 3).join('-')).valueOf(); var millis = Date.parse(parts.slice(0, 3).join('-')).valueOf();
var counter = parseInt(parts[3], 16); var counter = parseInt(parts[3], 16);
var node = parts[4]; var node = parts[4];
if (!isNaN(millis) && !isNaN(counter)) if (
!isNaN(millis) &&
millis >= 0 &&
!isNaN(counter) &&
counter <= MAX_COUNTER &&
typeof node === 'string' &&
node.length <= MAX_NODE_LENGTH
) {
return new Timestamp(millis, counter, node); return new Timestamp(millis, counter, node);
}
} }
} }
return null; return null;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment