Skip to content

Commit

Permalink
stricter int parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
danielrichman committed Mar 2, 2015
1 parent 572a3ad commit 4aa1c83
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions logtail.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ var reverse = true;
var log_data = "";
var log_file_size = 0;

/* :-( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt */
function parseInt2(value) {
if(!(/^[0-9]+$/.test(value))) throw "Invalid integer " + value;
var v = Number(value);
if (isNaN(v)) throw "Invalid integer " + value;
return v;
}

function get_log() {
if (kill | loading) return;
loading = true;
Expand Down Expand Up @@ -57,21 +65,18 @@ function get_log() {
if (!c_r)
throw "Server did not respond with a Content-Range";

log_file_size = parseInt(c_r.split("/")[1]);
content_size = parseInt(xhr.getResponseHeader("Content-Length"));
log_file_size = parseInt2(c_r.split("/")[1]);
content_size = parseInt2(xhr.getResponseHeader("Content-Length"));
} else if (xhr.status === 200) {
if (must_get_206)
throw "Expected 206 Partial Content";

content_size = log_file_size =
parseInt(xhr.getResponseHeader("Content-Length"));
parseInt2(xhr.getResponseHeader("Content-Length"));
} else {
throw "Unexpected status " + xhr.status;
}

if (isNaN(content_size) || isNaN(log_file_size))
throw "Invalid content_size or log_file_size";

if (first_load && data.length > load)
throw "Server's response was too long";

Expand Down

0 comments on commit 4aa1c83

Please sign in to comment.