add protection against requesting direct service files
This commit is contained in:
@@ -199,6 +199,37 @@ class WTVShared {
|
||||
return path.reverse().split(".")[0].reverse();
|
||||
}
|
||||
|
||||
getLineFromFile(filename, line_no, callback) {
|
||||
var stream = this.fs.createReadStream(filename, {
|
||||
flags: 'r',
|
||||
encoding: 'utf-8',
|
||||
fd: null,
|
||||
bufferSize: 64 * 1024
|
||||
});
|
||||
|
||||
|
||||
var fileData = '';
|
||||
stream.on('data', function (data) {
|
||||
fileData += data;
|
||||
|
||||
// The next lines should be improved
|
||||
var lines = fileData.split("\n");
|
||||
|
||||
if (lines.length >= +line_no) {
|
||||
stream.destroy();
|
||||
callback(null, lines[+line_no]);
|
||||
}
|
||||
});
|
||||
|
||||
stream.on('error', function () {
|
||||
callback('Error', null);
|
||||
});
|
||||
|
||||
stream.on('end', function () {
|
||||
callback('File end reached without finding line', null);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Strips bad things from paths
|
||||
* @param {string} base Base path
|
||||
|
||||
Reference in New Issue
Block a user