systeminformation 5.6.3 → 5.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -77,7 +77,8 @@ For major (breaking) changes - **version 4, 3 and 2** - see end of page.
77
77
 
78
78
  | Version | Date | Comment |
79
79
  | -------------- | -------------- | -------- |
80
- | 5.6.3 | 2021-03-10 | `sanitizeShellString()` improvement |
80
+ | 5.6.4 | 2021-03-15 | `sanitizeShellString()` and other security improvements |
81
+ | 5.6.3 | 2021-03-14 | `sanitizeShellString()` improvement |
81
82
  | 5.6.2 | 2021-03-10 | `networkInterfaces()` `cpu()` improvement (win) |
82
83
  | 5.6.1 | 2021-03-03 | `get()` fixed issue boolean parameters |
83
84
  | 5.6.0 | 2021-03-03 | `cpuTemperature()` added socket and chipset temp (linux) |
package/lib/docker.js CHANGED
@@ -470,7 +470,7 @@ function dockerContainerStats(containerIDs, callback) {
470
470
  if (containerIDsSanitized !== '*') {
471
471
  containerIDsSanitized = '';
472
472
  const s = (util.isPrototypePolluted() ? '' : util.sanitizeShellString(containerIDs, true)).trim();
473
- for (let i = 0; i <= 2000; i++) {
473
+ for (let i = 0; i <= util.mathMin(s.length, 2000); i++) {
474
474
  if (!(s[i] === undefined)) {
475
475
  s[i].__proto__.toLowerCase = util.stringToLower;
476
476
  const sl = s[i].toLowerCase();
package/lib/internet.js CHANGED
@@ -13,8 +13,7 @@
13
13
  // 12. Internet
14
14
  // ----------------------------------------------------------------------------------
15
15
 
16
- const exec = require('child_process').exec;
17
- const execFile = require('child_process').execFile;
16
+ // const exec = require('child_process').exec;
18
17
  const util = require('./util');
19
18
 
20
19
  let _platform = process.platform;
@@ -46,11 +45,11 @@ function inetChecksite(url, callback) {
46
45
  }
47
46
  let urlSanitized = '';
48
47
  const s = util.sanitizeShellString(url, true);
49
- for (let i = 0; i <= 2000; i++) {
48
+ for (let i = 0; i <= util.mathMin(s.length, 2000); i++) {
50
49
  if (!(s[i] === undefined)) {
51
50
  s[i].__proto__.toLowerCase = util.stringToLower;
52
51
  const sl = s[i].toLowerCase();
53
- if (sl && sl[0] && !sl[1]) {
52
+ if (sl && sl[0] && !sl[1] && sl[0].length === 1) {
54
53
  urlSanitized = urlSanitized + sl[0];
55
54
  }
56
55
  }
@@ -65,12 +64,14 @@ function inetChecksite(url, callback) {
65
64
  }
66
65
  let t = Date.now();
67
66
  if (_linux || _freebsd || _openbsd || _netbsd || _darwin || _sunos) {
68
- let args = ' -I --connect-timeout 5 -m 5 ' + urlSanitized + ' 2>/dev/null | head -n 1 | cut -d " " -f2';
67
+ let args = ['-I', '--connect-timeout', '5', '-m', '5'];
68
+ args.push(urlSanitized);
69
69
  let cmd = 'curl';
70
- exec(cmd + args, function (error, stdout) {
71
- let statusCode = parseInt(stdout.toString());
70
+ util.execSave(cmd, args).then((stdout) => {
71
+ const lines = stdout.split('\n');
72
+ let statusCode = lines[0] && lines[0].indexOf(' ') >= 0 ? parseInt(lines[0].split(' ')[1], 10) : 404;
72
73
  result.status = statusCode || 404;
73
- result.ok = !error && (statusCode === 200 || statusCode === 301 || statusCode === 302 || statusCode === 304);
74
+ result.ok = (statusCode === 200 || statusCode === 301 || statusCode === 302 || statusCode === 304);
74
75
  result.ms = (result.ok ? Date.now() - t : null);
75
76
  if (callback) { callback(result); }
76
77
  resolve(result);
@@ -142,7 +143,7 @@ function inetLatency(host, callback) {
142
143
  }
143
144
  let hostSanitized = '';
144
145
  const s = (util.isPrototypePolluted() ? '8.8.8.8' : util.sanitizeShellString(host, true)).trim();
145
- for (let i = 0; i <= 2000; i++) {
146
+ for (let i = 0; i <= util.mathMin(s.length, 2000); i++) {
146
147
  if (!(s[i] === undefined)) {
147
148
  s[i].__proto__.toLowerCase = util.stringToLower;
148
149
  const sl = s[i].toLowerCase();
@@ -171,10 +172,10 @@ function inetLatency(host, callback) {
171
172
  params = '-c2 -t3 ' + hostSanitized;
172
173
  filt = 'avg';
173
174
  }
174
- execFile('ping', params.split(' '), function (error, stdout) {
175
+ util.execSave('ping', params.split(' ')).then((stdout) => {
175
176
  let result = null;
176
- if (!error) {
177
- const lines = stdout.toString().split('\n').filter(line => line.indexOf(filt) >= 0).join('\n');
177
+ if (stdout) {
178
+ const lines = stdout.split('\n').filter(line => line.indexOf(filt) >= 0).join('\n');
178
179
 
179
180
  const line = lines.split('=');
180
181
  if (line.length > 1) {
@@ -191,10 +192,10 @@ function inetLatency(host, callback) {
191
192
  if (_sunos) {
192
193
  const params = '-s -a ' + hostSanitized + ' 56 2';
193
194
  const filt = 'avg';
194
- execFile('ping', params.split(' '), { timeout: 3000 }, function (error, stdout) {
195
+ util.execSave('ping', params.split(' '), { timeout: 3000 }).then((stdout) => {
195
196
  let result = null;
196
- if (!error) {
197
- const lines = stdout.toString().split('\n').filter(line => line.indexOf(filt) >= 0).join('\n');
197
+ if (stdout) {
198
+ const lines = stdout.split('\n').filter(line => line.indexOf(filt) >= 0).join('\n');
198
199
  const line = lines.split('=');
199
200
  if (line.length > 1) {
200
201
  const parts = line[1].split('/');
@@ -211,9 +212,9 @@ function inetLatency(host, callback) {
211
212
  let result = null;
212
213
  try {
213
214
  const params = hostSanitized + ' -n 1';
214
- execFile('ping', params.split(' '), util.execOptsWin, function (error, stdout) {
215
- if (!error) {
216
- let lines = stdout.toString().split('\r\n');
215
+ util.execSave('ping', params.split(' '), util.execOptsWin).then((stdout) => {
216
+ if (stdout) {
217
+ let lines = stdout.split('\r\n');
217
218
  lines.shift();
218
219
  lines.forEach(function (line) {
219
220
  if ((line.toLowerCase().match(/ms/g) || []).length === 3) {
package/lib/network.js CHANGED
@@ -1061,7 +1061,7 @@ function networkStatsSingle(iface) {
1061
1061
  process.nextTick(() => {
1062
1062
  let ifaceSanitized = '';
1063
1063
  const s = util.isPrototypePolluted() ? '---' : util.sanitizeShellString(iface);
1064
- for (let i = 0; i <= 2000; i++) {
1064
+ for (let i = 0; i <= util.mathMin(s.length, 2000); i++) {
1065
1065
  if (!(s[i] === undefined)) {
1066
1066
  ifaceSanitized = ifaceSanitized + s[i];
1067
1067
  }
package/lib/processes.js CHANGED
@@ -111,7 +111,7 @@ function services(srv, callback) {
111
111
  srvString.__proto__.trim = util.stringTrim;
112
112
 
113
113
  const s = util.sanitizeShellString(srv);
114
- for (let i = 0; i <= 2000; i++) {
114
+ for (let i = 0; i <= util.mathMin(s.length, 2000); i++) {
115
115
  if (!(s[i] === undefined)) {
116
116
  srvString = srvString + s[i];
117
117
  }
@@ -164,15 +164,15 @@ function services(srv, callback) {
164
164
  }
165
165
  }
166
166
  }
167
- if ((_darwin) && srvString === '*') { // service enumeration mnot yet suported on mac OS
167
+ if ((_darwin) && srvString === '*') { // service enumeration not yet suported on mac OS
168
168
  if (callback) { callback(result); }
169
169
  resolve(result);
170
170
  }
171
- let comm = (_darwin) ? 'ps -caxo pcpu,pmem,pid,command' : 'ps -axo pcpu,pmem,pid,command';
171
+ let args = (_darwin) ? ['-caxo', 'pcpu,pmem,pid,command'] : ['-axo', 'pcpu,pmem,pid,command'];
172
172
  if (srvString !== '' && srvs.length > 0) {
173
- exec(comm + ' | grep -v grep | grep -iE "' + srvString + '"', { maxBuffer: 1024 * 20000 }, function (error, stdout) { // lgtm [js/shell-command-constructed-from-input]
174
- if (!error) {
175
- let lines = stdout.toString().replace(/ +/g, ' ').replace(/,+/g, '.').split('\n');
173
+ util.execSave('ps', args).then((stdout) => {
174
+ if (stdout) {
175
+ let lines = stdout.replace(/ +/g, ' ').replace(/,+/g, '.').split('\n');
176
176
  srvs.forEach(function (srv) {
177
177
  let ps;
178
178
  if (_darwin) {
@@ -267,9 +267,10 @@ function services(srv, callback) {
267
267
  resolve(result);
268
268
  }
269
269
  } else {
270
- exec('ps -o comm | grep -v grep | egrep "' + srvString + '"', { maxBuffer: 1024 * 20000 }, function (error, stdout) { // lgtm [js/shell-command-constructed-from-input]
271
- if (!error) {
272
- let lines = stdout.toString().replace(/ +/g, ' ').replace(/,+/g, '.').split('\n');
270
+ args = ['-o', 'comm'];
271
+ util.execSave('ps', args).then((stdout) => {
272
+ if (stdout) {
273
+ let lines = stdout.replace(/ +/g, ' ').replace(/,+/g, '.').split('\n');
273
274
  srvs.forEach(function (srv) {
274
275
  let ps = lines.filter(function (e) {
275
276
  return e.indexOf(srv) !== -1;
@@ -909,7 +910,7 @@ function processLoad(proc, callback) {
909
910
  processesString.__proto__.trim = util.stringTrim;
910
911
 
911
912
  const s = util.sanitizeShellString(proc);
912
- for (let i = 0; i <= 2000; i++) {
913
+ for (let i = 0; i <= util.mathMin(s.length, 2000); i++) {
913
914
  if (!(s[i] === undefined)) {
914
915
  processesString = processesString + s[i];
915
916
  }
package/lib/util.js CHANGED
@@ -58,6 +58,7 @@ const stringToString = new String().toString;
58
58
  const stringSubstr = new String().substr;
59
59
  const stringTrim = new String().trim;
60
60
  const stringStartWith = new String().startsWith;
61
+ const mathMin = Math.min;
61
62
 
62
63
  function isFunction(functionToCheck) {
63
64
  let getType = {};
@@ -389,6 +390,42 @@ function powerShell(cmd) {
389
390
  });
390
391
  }
391
392
 
393
+ function execSave(cmd, args, options) {
394
+ let result = '';
395
+ options = options || {};
396
+
397
+ return new Promise((resolve) => {
398
+ process.nextTick(() => {
399
+ try {
400
+ const child = spawn(cmd, args, options);
401
+
402
+ if (child && !child.pid) {
403
+ child.on('error', function () {
404
+ resolve(result);
405
+ });
406
+ }
407
+ if (child && child.pid) {
408
+ child.stdout.on('data', function (data) {
409
+ result += data.toString();
410
+ });
411
+ child.on('close', function () {
412
+ child.kill();
413
+ resolve(result);
414
+ });
415
+ child.on('error', function () {
416
+ child.kill();
417
+ resolve(result);
418
+ });
419
+ } else {
420
+ resolve(result);
421
+ }
422
+ } catch (e) {
423
+ resolve(result);
424
+ }
425
+ });
426
+ });
427
+ }
428
+
392
429
  function getCodepage() {
393
430
  if (_windows) {
394
431
  if (!codepage) {
@@ -506,7 +543,7 @@ function countLines(lines, startingWith) {
506
543
  function sanitizeShellString(str, strict = false) {
507
544
  const s = str || '';
508
545
  let result = '';
509
- for (let i = 0; i <= 2000; i++) {
546
+ for (let i = 0; i <= mathMin(s.length, 2000); i++) {
510
547
  if (!(s[i] === undefined ||
511
548
  s[i] === '>' ||
512
549
  s[i] === '<' ||
@@ -925,6 +962,7 @@ exports.wmic = wmic;
925
962
  exports.darwinXcodeExists = darwinXcodeExists;
926
963
  exports.getVboxmanage = getVboxmanage;
927
964
  exports.powerShell = powerShell;
965
+ exports.execSave = execSave;
928
966
  exports.nanoSeconds = nanoSeconds;
929
967
  exports.countUniqueLines = countUniqueLines;
930
968
  exports.countLines = countLines;
@@ -943,5 +981,6 @@ exports.stringToString = stringToString;
943
981
  exports.stringSubstr = stringSubstr;
944
982
  exports.stringTrim = stringTrim;
945
983
  exports.stringStartWith = stringStartWith;
984
+ exports.mathMin = mathMin;
946
985
  exports.WINDIR = WINDIR;
947
986
  exports.getFilesInPath = getFilesInPath;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "systeminformation",
3
- "version": "5.6.3",
3
+ "version": "5.6.4",
4
4
  "description": "Simple system and OS information library",
5
5
  "license": "MIT",
6
6
  "author": "Sebastian Hildebrandt <hildebrandt@plus-innovations.com> (https://plus-innovations.com)",