net-snmp 3.28.0 → 3.28.1

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.
Files changed (3) hide show
  1. package/README.md +6 -0
  2. package/index.js +56 -16
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -3779,6 +3779,12 @@ Example programs are included under the module's `example` directory.
3779
3779
 
3780
3780
  * Replace `.npmignore` with a `files` allowlist in `package.json`, so the published package ships only the module, its libraries, examples and reference files
3781
3781
 
3782
+ # Version 3.28.1 - 12/09/2026
3783
+
3784
+ * Reject table instance OIDs whose row index encoding is malformed, instead of silently decoding them to a different row - a SetRequest naming a non-implied `OctetString` or OID index that claimed a different length than it supplied, or that carried unexpected trailing components, would create a row at the decoded index while answering `NoSuchInstance` for the OID that was requested
3785
+
3786
+ * Decode index parts declared with a fixed `length` without consuming a leading length component, matching the way they are encoded - an index value of `AB` in such a column previously read back as `B`
3787
+
3782
3788
  # License
3783
3789
 
3784
3790
  Copyright (c) 2020 Mark Abrahams <mark@abrahams.co.nz>
package/index.js CHANGED
@@ -4707,41 +4707,73 @@ Mib.prototype.getTableRowInstanceFromRow = function (provider, row) {
4707
4707
  return rowIndex;
4708
4708
  };
4709
4709
 
4710
+ // Splices exactly `length` components off the front of an index address,
4711
+ // rejecting encodings that claim more components than they supply.
4712
+ Mib.spliceIndexValue = function (addressRemaining, length, oid) {
4713
+ var value = addressRemaining.splice (0, length);
4714
+ if ( value.length !== length ) {
4715
+ throw new RangeError ("Index encoding in \"" + oid + "\" claims " + length +
4716
+ " components but supplies " + value.length);
4717
+ }
4718
+ return value;
4719
+ };
4720
+
4721
+ // Determines how many OID components an index part occupies, consuming a
4722
+ // leading length component for variable-length parts that are neither
4723
+ // implied nor of a fixed length.
4724
+ Mib.getIndexPartLength = function (indexPart, addressRemaining, oid) {
4725
+ var length;
4726
+ if ( indexPart.implied ) {
4727
+ return addressRemaining.length;
4728
+ }
4729
+ if ( indexPart.length ) {
4730
+ return indexPart.length;
4731
+ }
4732
+ length = Number (addressRemaining.shift ());
4733
+ if ( ! Number.isInteger (length) || length < 0 ) {
4734
+ throw new RangeError ("Index encoding in \"" + oid + "\" has a missing or invalid length component");
4735
+ }
4736
+ return length;
4737
+ };
4738
+
4710
4739
  Mib.getRowIndexFromOid = function (oid, index) {
4711
- var addressRemaining = oid.split (".");
4740
+ var addressRemaining = oid === "" ? [] : oid.split (".");
4712
4741
  var length = 0;
4713
4742
  var values = [];
4714
4743
  var value;
4715
4744
  for ( var indexPart of index ) {
4716
4745
  switch ( indexPart.type ) {
4717
4746
  case ObjectType.OID:
4718
- if ( indexPart.implied ) {
4719
- length = addressRemaining.length;
4720
- } else {
4721
- length = addressRemaining.shift ();
4722
- }
4723
- value = addressRemaining.splice (0, length);
4747
+ length = Mib.getIndexPartLength (indexPart, addressRemaining, oid);
4748
+ value = Mib.spliceIndexValue (addressRemaining, length, oid);
4724
4749
  values.push (value.join ("."));
4725
4750
  break;
4726
4751
  case ObjectType.IpAddress:
4727
4752
  length = 4;
4728
- value = addressRemaining.splice (0, length);
4753
+ value = Mib.spliceIndexValue (addressRemaining, length, oid);
4729
4754
  values.push (value.join ("."));
4730
4755
  break;
4731
4756
  case ObjectType.OctetString:
4732
- if ( indexPart.implied ) {
4733
- length = addressRemaining.length;
4734
- } else {
4735
- length = addressRemaining.shift ();
4736
- }
4737
- value = addressRemaining.splice (0, length);
4757
+ length = Mib.getIndexPartLength (indexPart, addressRemaining, oid);
4758
+ value = Mib.spliceIndexValue (addressRemaining, length, oid);
4738
4759
  value = value.map (c => String.fromCharCode(c)).join ("");
4739
4760
  values.push (value);
4740
4761
  break;
4741
4762
  default:
4742
- values.push (parseInt (addressRemaining.shift ()) );
4763
+ if ( addressRemaining.length === 0 ) {
4764
+ throw new RangeError ("Index encoding in \"" + oid + "\" is missing a component");
4765
+ }
4766
+ value = parseInt (addressRemaining.shift ());
4767
+ if ( Number.isNaN (value) ) {
4768
+ throw new RangeError ("Index encoding in \"" + oid + "\" has a non-numeric component");
4769
+ }
4770
+ values.push (value);
4743
4771
  }
4744
4772
  }
4773
+ if ( addressRemaining.length > 0 ) {
4774
+ throw new RangeError ("Index encoding in \"" + oid + "\" has " + addressRemaining.length +
4775
+ " unexpected trailing component(s)");
4776
+ }
4745
4777
  return values;
4746
4778
  };
4747
4779
 
@@ -5297,7 +5329,15 @@ Agent.prototype.tryCreateInstance = function (varbind, requestType) {
5297
5329
  subOid = Mib.getSubOidFromBaseOid (oid, provider.oid);
5298
5330
  subAddr = subOid.split(".");
5299
5331
  column = parseInt(subAddr.shift(), 10);
5300
- row = Mib.getRowIndexFromOid(subAddr.join("."), provider.tableIndex);
5332
+ try {
5333
+ row = Mib.getRowIndexFromOid(subAddr.join("."), provider.tableIndex);
5334
+ } catch (error) {
5335
+ // The OID is not a valid index encoding for this table, so it names no
5336
+ // row and there is nothing to create. Leave the varbind to be answered
5337
+ // as NoSuchInstance.
5338
+ debug (error);
5339
+ return undefined;
5340
+ }
5301
5341
  rowStatusColumn = provider.tableColumns.reduce( (acc, current) => current.rowStatus ? current.number : acc, null );
5302
5342
 
5303
5343
  if ( requestType === PduType.SetRequest &&
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "net-snmp",
3
- "version": "3.28.0",
3
+ "version": "3.28.1",
4
4
  "description": "JavaScript implementation of the Simple Network Management Protocol (SNMP)",
5
5
  "author": "Mark Abrahams <mark@abrahams.co.nz>",
6
6
  "license": "MIT",