net-snmp 3.7.2 → 3.8.0
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/.travis.yml +1 -1
- package/README.md +4 -0
- package/index.js +91 -107
- package/package.json +2 -2
package/.travis.yml
CHANGED
package/README.md
CHANGED
@@ -3211,6 +3211,10 @@ Example programs are included under the module's `example` directory.
|
|
3211
3211
|
|
3212
3212
|
* Improve getBulk response handling
|
3213
3213
|
|
3214
|
+
## Version 3.8.0 - 07/06/2022
|
3215
|
+
|
3216
|
+
* Fix 32-bit unsigned integer writing
|
3217
|
+
|
3214
3218
|
# License
|
3215
3219
|
|
3216
3220
|
Copyright (c) 2020 Mark Abrahams <mark@abrahams.co.nz>
|
package/index.js
CHANGED
@@ -11,7 +11,10 @@ var crypto = require ("crypto");
|
|
11
11
|
var mibparser = require ("./lib/mib");
|
12
12
|
var DEBUG = false;
|
13
13
|
|
14
|
-
var
|
14
|
+
var MIN_SIGNED_INT32 = -2147483648;
|
15
|
+
var MAX_SIGNED_INT32 = 2147483647;
|
16
|
+
var MIN_UNSIGNED_INT32 = 0;
|
17
|
+
var MAX_UNSIGNED_INT32 = 4294967295;
|
15
18
|
|
16
19
|
function debug (line) {
|
17
20
|
if ( DEBUG ) {
|
@@ -378,71 +381,26 @@ function oidInSubtree (oidString, nextString) {
|
|
378
381
|
return true;
|
379
382
|
}
|
380
383
|
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
** with this, instead opting to work around it here.
|
386
|
-
**
|
387
|
-
** If an integer is 5 bytes in length we check if the first byte is 0, and if so
|
388
|
-
** simply drop it and parse it like it was a 4 byte integer, otherwise throw
|
389
|
-
** an error since the integer is too large.
|
390
|
-
**/
|
391
|
-
|
392
|
-
function readInt (buffer) {
|
393
|
-
return readUint (buffer, true);
|
394
|
-
}
|
395
|
-
|
396
|
-
function readIpAddress (buffer) {
|
397
|
-
var bytes = buffer.readString (ObjectType.IpAddress, true);
|
398
|
-
if (bytes.length != 4)
|
399
|
-
throw new ResponseInvalidError ("Length '" + bytes.length
|
400
|
-
+ "' of IP address '" + bytes.toString ("hex")
|
401
|
-
+ "' is not 4", ResponseInvalidCode.EIp4AddressSize);
|
402
|
-
var value = bytes[0] + "." + bytes[1] + "." + bytes[2] + "." + bytes[3];
|
403
|
-
return value;
|
404
|
-
}
|
405
|
-
|
406
|
-
function readUint (buffer, isSigned) {
|
407
|
-
buffer.readByte ();
|
408
|
-
var length = buffer.readByte ();
|
409
|
-
var value = 0;
|
410
|
-
var signedBitSet = false;
|
411
|
-
|
412
|
-
// Handle BER long-form length encoding
|
413
|
-
if ((length & 0x80) == 0x80) {
|
414
|
-
var lengthOctets = (length & 0x7f);
|
415
|
-
length = 0;
|
416
|
-
for (var lengthOctet = 0; lengthOctet < lengthOctets; lengthOctet++) {
|
417
|
-
length *= 256;
|
418
|
-
length += buffer.readByte ();
|
419
|
-
}
|
384
|
+
function readInt32 (buffer) {
|
385
|
+
var parsedInt = buffer.readInt ();
|
386
|
+
if ( ! Number.isInteger(parsedInt) ) {
|
387
|
+
throw new TypeError('Value read as integer ' + parsedInt + ' is not an integer');
|
420
388
|
}
|
421
|
-
|
422
|
-
|
423
|
-
throw new RangeError ("Integer too long '" + length + "'");
|
424
|
-
} else if (length == 5) {
|
425
|
-
if (buffer.readByte () !== 0)
|
426
|
-
throw new RangeError ("Integer too long '" + length + "'");
|
427
|
-
length = 4;
|
389
|
+
if ( parsedInt < MIN_SIGNED_INT32 || parsedInt > MAX_SIGNED_INT32 ) {
|
390
|
+
throw new RangeError('Read integer ' + parsedInt + ' is outside the signed 32-bit range');
|
428
391
|
}
|
392
|
+
return parsedInt;
|
393
|
+
}
|
429
394
|
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
if (isSigned && i <= 0) {
|
435
|
-
if ((value & 0x80) == 0x80) {
|
436
|
-
signedBitSet = true;
|
437
|
-
}
|
438
|
-
}
|
395
|
+
function readUint32 (buffer) {
|
396
|
+
var parsedInt = buffer.readInt ();
|
397
|
+
if ( ! Number.isInteger(parsedInt) ) {
|
398
|
+
throw new TypeError('Value read as integer ' + parsedInt + ' is not an integer');
|
439
399
|
}
|
440
|
-
|
441
|
-
|
442
|
-
value -= 2 ** (i * 8);
|
400
|
+
if ( parsedInt < MIN_UNSIGNED_INT32 || parsedInt > MAX_UNSIGNED_INT32 ) {
|
401
|
+
throw new RangeError('Read integer ' + parsedInt + ' is outside the unsigned 32-bit range');
|
443
402
|
}
|
444
|
-
|
445
|
-
return value;
|
403
|
+
return parsedInt;
|
446
404
|
}
|
447
405
|
|
448
406
|
function readUint64 (buffer) {
|
@@ -451,12 +409,22 @@ function readUint64 (buffer) {
|
|
451
409
|
return value;
|
452
410
|
}
|
453
411
|
|
412
|
+
function readIpAddress (buffer) {
|
413
|
+
var bytes = buffer.readString (ObjectType.IpAddress, true);
|
414
|
+
if (bytes.length != 4)
|
415
|
+
throw new ResponseInvalidError ("Length '" + bytes.length
|
416
|
+
+ "' of IP address '" + bytes.toString ("hex")
|
417
|
+
+ "' is not 4", ResponseInvalidCode.EIp4AddressSize);
|
418
|
+
var value = bytes[0] + "." + bytes[1] + "." + bytes[2] + "." + bytes[3];
|
419
|
+
return value;
|
420
|
+
}
|
421
|
+
|
454
422
|
function readVarbindValue (buffer, type) {
|
455
423
|
var value;
|
456
424
|
if (type == ObjectType.Boolean) {
|
457
425
|
value = buffer.readBoolean ();
|
458
426
|
} else if (type == ObjectType.Integer) {
|
459
|
-
value =
|
427
|
+
value = readInt32 (buffer);
|
460
428
|
} else if (type == ObjectType.OctetString) {
|
461
429
|
value = buffer.readString (null, true);
|
462
430
|
} else if (type == ObjectType.Null) {
|
@@ -468,11 +436,11 @@ function readVarbindValue (buffer, type) {
|
|
468
436
|
} else if (type == ObjectType.IpAddress) {
|
469
437
|
value = readIpAddress (buffer);
|
470
438
|
} else if (type == ObjectType.Counter) {
|
471
|
-
value =
|
439
|
+
value = readUint32 (buffer);
|
472
440
|
} else if (type == ObjectType.Gauge) {
|
473
|
-
value =
|
441
|
+
value = readUint32 (buffer);
|
474
442
|
} else if (type == ObjectType.TimeTicks) {
|
475
|
-
value =
|
443
|
+
value = readUint32 (buffer);
|
476
444
|
} else if (type == ObjectType.Opaque) {
|
477
445
|
value = buffer.readString (ObjectType.Opaque, true);
|
478
446
|
} else if (type == ObjectType.Counter64) {
|
@@ -519,10 +487,24 @@ function readVarbinds (buffer, varbinds) {
|
|
519
487
|
}
|
520
488
|
}
|
521
489
|
|
522
|
-
function
|
523
|
-
|
524
|
-
|
525
|
-
|
490
|
+
function writeInt32 (buffer, type, value) {
|
491
|
+
if ( ! Number.isInteger(value) ) {
|
492
|
+
throw new TypeError('Value to write as integer ' + value + ' is not an integer');
|
493
|
+
}
|
494
|
+
if ( value < MIN_SIGNED_INT32 || value > MAX_SIGNED_INT32 ) {
|
495
|
+
throw new RangeError('Integer to write ' + value + ' is outside the signed 32-bit range');
|
496
|
+
}
|
497
|
+
buffer.writeInt(value, type);
|
498
|
+
}
|
499
|
+
|
500
|
+
function writeUint32 (buffer, type, value) {
|
501
|
+
if ( ! Number.isInteger(value) ) {
|
502
|
+
throw new TypeError('Value to write as integer ' + value + ' is not an integer');
|
503
|
+
}
|
504
|
+
if ( value < MIN_UNSIGNED_INT32 || value > MAX_UNSIGNED_INT32 ) {
|
505
|
+
throw new RangeError('Integer to write ' + value + ' is outside the unsigned 32-bit range');
|
506
|
+
}
|
507
|
+
buffer.writeInt(value, type);
|
526
508
|
}
|
527
509
|
|
528
510
|
function writeUint64 (buffer, value) {
|
@@ -544,7 +526,7 @@ function writeVarbinds (buffer, varbinds) {
|
|
544
526
|
buffer.writeBoolean (value ? true : false);
|
545
527
|
break;
|
546
528
|
case ObjectType.Integer: // also Integer32
|
547
|
-
buffer.
|
529
|
+
writeInt32 (buffer, ObjectType.Integer, value);
|
548
530
|
break;
|
549
531
|
case ObjectType.OctetString:
|
550
532
|
if (typeof value == "string")
|
@@ -566,13 +548,13 @@ function writeVarbinds (buffer, varbinds) {
|
|
566
548
|
buffer.writeBuffer (Buffer.from (bytes), 64);
|
567
549
|
break;
|
568
550
|
case ObjectType.Counter: // also Counter32
|
569
|
-
|
551
|
+
writeUint32 (buffer, ObjectType.Counter, value);
|
570
552
|
break;
|
571
553
|
case ObjectType.Gauge: // also Gauge32 & Unsigned32
|
572
|
-
|
554
|
+
writeUint32 (buffer, ObjectType.Gauge, value);
|
573
555
|
break;
|
574
556
|
case ObjectType.TimeTicks:
|
575
|
-
|
557
|
+
writeUint32 (buffer, ObjectType.TimeTicks, value);
|
576
558
|
break;
|
577
559
|
case ObjectType.Opaque:
|
578
560
|
buffer.writeBuffer (value, ObjectType.Opaque);
|
@@ -609,11 +591,13 @@ var SimplePdu = function () {
|
|
609
591
|
SimplePdu.prototype.toBuffer = function (buffer) {
|
610
592
|
buffer.startSequence (this.type);
|
611
593
|
|
612
|
-
buffer.
|
613
|
-
|
594
|
+
writeInt32 (buffer, ObjectType.Integer, this.id);
|
595
|
+
writeInt32 (buffer, ObjectType.Integer,
|
596
|
+
(this.type == PduType.GetBulkRequest)
|
614
597
|
? (this.options.nonRepeaters || 0)
|
615
598
|
: 0);
|
616
|
-
|
599
|
+
writeInt32 (buffer, ObjectType.Integer,
|
600
|
+
(this.type == PduType.GetBulkRequest)
|
617
601
|
? (this.options.maxRepetitions || 0)
|
618
602
|
: 0);
|
619
603
|
|
@@ -633,9 +617,9 @@ SimplePdu.prototype.initializeFromBuffer = function (reader) {
|
|
633
617
|
this.type = reader.peek ();
|
634
618
|
reader.readSequence ();
|
635
619
|
|
636
|
-
this.id =
|
637
|
-
this.nonRepeaters =
|
638
|
-
this.maxRepetitions =
|
620
|
+
this.id = readInt32 (reader);
|
621
|
+
this.nonRepeaters = readInt32 (reader);
|
622
|
+
this.maxRepetitions = readInt32 (reader);
|
639
623
|
|
640
624
|
this.varbinds = [];
|
641
625
|
readVarbinds (reader, this.varbinds);
|
@@ -740,9 +724,9 @@ TrapPdu.prototype.toBuffer = function (buffer) {
|
|
740
724
|
buffer.writeOID (this.enterprise);
|
741
725
|
buffer.writeBuffer (Buffer.from (this.agentAddr.split (".")),
|
742
726
|
ObjectType.IpAddress);
|
743
|
-
buffer.
|
744
|
-
buffer.
|
745
|
-
|
727
|
+
writeInt32 (buffer, ObjectType.Integer, this.generic);
|
728
|
+
writeInt32 (buffer, ObjectType.Integer, this.specific);
|
729
|
+
writeUint32 (buffer, ObjectType.TimeTicks,
|
746
730
|
this.upTime || Math.floor (process.uptime () * 100));
|
747
731
|
|
748
732
|
writeVarbinds (buffer, this.varbinds);
|
@@ -756,9 +740,9 @@ TrapPdu.createFromBuffer = function (reader) {
|
|
756
740
|
|
757
741
|
pdu.enterprise = reader.readOID ();
|
758
742
|
pdu.agentAddr = readIpAddress (reader);
|
759
|
-
pdu.generic =
|
760
|
-
pdu.specific =
|
761
|
-
pdu.upTime =
|
743
|
+
pdu.generic = readInt32 (reader);
|
744
|
+
pdu.specific = readInt32 (reader);
|
745
|
+
pdu.upTime = readUint32 (reader);
|
762
746
|
|
763
747
|
pdu.varbinds = [];
|
764
748
|
readVarbinds (reader, pdu.varbinds);
|
@@ -811,9 +795,9 @@ var SimpleResponsePdu = function() {
|
|
811
795
|
SimpleResponsePdu.prototype.toBuffer = function (writer) {
|
812
796
|
writer.startSequence (this.type);
|
813
797
|
|
814
|
-
writer.
|
815
|
-
writer
|
816
|
-
writer.
|
798
|
+
writeInt32 (writer, ObjectType.Integer, this.id);
|
799
|
+
writeInt32 (writer, this.errorStatus || 0);
|
800
|
+
writeInt32 (writer, ObjectType.Integer, this.errorIndex || 0);
|
817
801
|
writeVarbinds (writer, this.varbinds);
|
818
802
|
writer.endSequence ();
|
819
803
|
|
@@ -822,9 +806,9 @@ SimpleResponsePdu.prototype.toBuffer = function (writer) {
|
|
822
806
|
SimpleResponsePdu.prototype.initializeFromBuffer = function (reader) {
|
823
807
|
reader.readSequence (this.type);
|
824
808
|
|
825
|
-
this.id =
|
826
|
-
this.errorStatus =
|
827
|
-
this.errorIndex =
|
809
|
+
this.id = readInt32 (reader);
|
810
|
+
this.errorStatus = readInt32 (reader);
|
811
|
+
this.errorIndex = readInt32 (reader);
|
828
812
|
|
829
813
|
this.varbinds = [];
|
830
814
|
readVarbinds (reader, this.varbinds);
|
@@ -1335,7 +1319,7 @@ Message.prototype.toBufferCommunity = function () {
|
|
1335
1319
|
|
1336
1320
|
writer.startSequence ();
|
1337
1321
|
|
1338
|
-
writer.
|
1322
|
+
writeInt32 (writer, ObjectType.Integer, this.version);
|
1339
1323
|
writer.writeString (this.community);
|
1340
1324
|
|
1341
1325
|
this.pdu.toBuffer (writer);
|
@@ -1380,16 +1364,16 @@ Message.prototype.toBufferV3 = function () {
|
|
1380
1364
|
|
1381
1365
|
writer.startSequence ();
|
1382
1366
|
|
1383
|
-
writer.
|
1367
|
+
writeInt32 (writer, ObjectType.Integer, this.version);
|
1384
1368
|
|
1385
1369
|
// HeaderData
|
1386
1370
|
writer.startSequence ();
|
1387
|
-
writer.
|
1388
|
-
writer.
|
1371
|
+
writeInt32 (writer, ObjectType.Integer, this.msgGlobalData.msgID);
|
1372
|
+
writeInt32 (writer, ObjectType.Integer, this.msgGlobalData.msgMaxSize);
|
1389
1373
|
writer.writeByte (ber.OctetString);
|
1390
1374
|
writer.writeByte (1);
|
1391
1375
|
writer.writeByte (this.msgGlobalData.msgFlags);
|
1392
|
-
writer.
|
1376
|
+
writeInt32 (writer, ObjectType.Integer, this.msgGlobalData.msgSecurityModel);
|
1393
1377
|
writer.endSequence ();
|
1394
1378
|
|
1395
1379
|
// msgSecurityParameters
|
@@ -1402,8 +1386,8 @@ Message.prototype.toBufferV3 = function () {
|
|
1402
1386
|
} else {
|
1403
1387
|
writer.writeBuffer (this.msgSecurityParameters.msgAuthoritativeEngineID, ber.OctetString);
|
1404
1388
|
}
|
1405
|
-
writer.
|
1406
|
-
writer.
|
1389
|
+
writeInt32 (writer, ObjectType.Integer, this.msgSecurityParameters.msgAuthoritativeEngineBoots);
|
1390
|
+
writeInt32 (writer, ObjectType.Integer, this.msgSecurityParameters.msgAuthoritativeEngineTime);
|
1407
1391
|
writer.writeString (this.msgSecurityParameters.msgUserName);
|
1408
1392
|
|
1409
1393
|
var msgAuthenticationParameters = '';
|
@@ -1663,7 +1647,7 @@ Message.createFromBuffer = function (buffer, user) {
|
|
1663
1647
|
|
1664
1648
|
reader.readSequence ();
|
1665
1649
|
|
1666
|
-
message.version =
|
1650
|
+
message.version = readInt32 (reader);
|
1667
1651
|
|
1668
1652
|
if (message.version != 3) {
|
1669
1653
|
message.community = reader.readString ();
|
@@ -1672,18 +1656,18 @@ Message.createFromBuffer = function (buffer, user) {
|
|
1672
1656
|
// HeaderData
|
1673
1657
|
message.msgGlobalData = {};
|
1674
1658
|
reader.readSequence ();
|
1675
|
-
message.msgGlobalData.msgID =
|
1676
|
-
message.msgGlobalData.msgMaxSize =
|
1659
|
+
message.msgGlobalData.msgID = readInt32 (reader);
|
1660
|
+
message.msgGlobalData.msgMaxSize = readInt32 (reader);
|
1677
1661
|
message.msgGlobalData.msgFlags = reader.readString (ber.OctetString, true)[0];
|
1678
|
-
message.msgGlobalData.msgSecurityModel =
|
1662
|
+
message.msgGlobalData.msgSecurityModel = readInt32 (reader);
|
1679
1663
|
|
1680
1664
|
// msgSecurityParameters
|
1681
1665
|
message.msgSecurityParameters = {};
|
1682
1666
|
var msgSecurityParametersReader = new ber.Reader (reader.readString (ber.OctetString, true));
|
1683
1667
|
msgSecurityParametersReader.readSequence ();
|
1684
1668
|
message.msgSecurityParameters.msgAuthoritativeEngineID = msgSecurityParametersReader.readString (ber.OctetString, true);
|
1685
|
-
message.msgSecurityParameters.msgAuthoritativeEngineBoots =
|
1686
|
-
message.msgSecurityParameters.msgAuthoritativeEngineTime =
|
1669
|
+
message.msgSecurityParameters.msgAuthoritativeEngineBoots = readInt32 (msgSecurityParametersReader);
|
1670
|
+
message.msgSecurityParameters.msgAuthoritativeEngineTime = readInt32 (msgSecurityParametersReader);
|
1687
1671
|
message.msgSecurityParameters.msgUserName = msgSecurityParametersReader.readString ();
|
1688
1672
|
message.msgSecurityParameters.msgAuthenticationParameters = msgSecurityParametersReader.readString (ber.OctetString, true);
|
1689
1673
|
message.msgSecurityParameters.msgPrivacyParameters = Buffer.from(msgSecurityParametersReader.readString (ber.OctetString, true));
|
@@ -4416,7 +4400,7 @@ Mib.convertOidToAddress = function (oid) {
|
|
4416
4400
|
throw new RangeError('object identifier component ' +
|
4417
4401
|
address[i] + ' is negative');
|
4418
4402
|
}
|
4419
|
-
if (n >
|
4403
|
+
if (n > MAX_SIGNED_INT32) {
|
4420
4404
|
throw new RangeError('object identifier component ' +
|
4421
4405
|
address[i] + ' is too large');
|
4422
4406
|
}
|
@@ -6230,8 +6214,8 @@ exports.RequestTimedOutError = RequestTimedOutError;
|
|
6230
6214
|
** Added for testing
|
6231
6215
|
**/
|
6232
6216
|
exports.ObjectParser = {
|
6233
|
-
|
6234
|
-
|
6217
|
+
readInt32: readInt32,
|
6218
|
+
readUint32: readUint32,
|
6235
6219
|
readVarbindValue: readVarbindValue
|
6236
6220
|
};
|
6237
6221
|
exports.Authentication = Authentication;
|
package/package.json
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
{
|
2
2
|
"name": "net-snmp",
|
3
|
-
"version": "3.
|
3
|
+
"version": "3.8.0",
|
4
4
|
"description": "JavaScript implementation of the Simple Network Management Protocol (SNMP)",
|
5
5
|
"main": "index.js",
|
6
6
|
"directories": {
|
7
7
|
"example": "example"
|
8
8
|
},
|
9
9
|
"dependencies": {
|
10
|
-
"asn1-ber": "
|
10
|
+
"asn1-ber": "^1.2.0",
|
11
11
|
"smart-buffer": "^4.1.0"
|
12
12
|
},
|
13
13
|
"devDependencies": {
|