net-snmp 3.9.1 → 3.9.2

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/README.md CHANGED
@@ -3247,6 +3247,10 @@ Example programs are included under the module's `example` directory.
3247
3247
 
3248
3248
  * Fix MIB parsing of unclosed brackets in comments
3249
3249
 
3250
+ ## Version 3.9.2 - 26/04/2023
3251
+
3252
+ * Fix MIB parsing of non-comments in descriptions and unmatched quotations
3253
+
3250
3254
  # License
3251
3255
 
3252
3256
  Copyright (c) 2020 Mark Abrahams <mark@abrahams.co.nz>
@@ -35,12 +35,26 @@ var mib = agent.getMib ();
35
35
  var authorizer = agent.getAuthorizer ();
36
36
  authorizer.addCommunity ("public");
37
37
 
38
+
38
39
  // IF-MIB load and providers registration
39
40
  store.loadFromFile (mibDir + "IANAifType-MIB.mib");
40
41
  store.loadFromFile (mibDir + "IF-MIB.mib");
41
42
  providers = store.getProvidersForModule ("IF-MIB");
42
43
  mib.registerProviders (providers);
43
44
 
45
+ store.loadFromFile (mibDir + "SNMP-FRAMEWORK-MIB.mib");
46
+ store.loadFromFile (mibDir + "INET-ADDRESS-MIB.mib");
47
+ store.loadFromFile (mibDir + "CISCO-SMI.mib");
48
+ store.loadFromFile (mibDir + "CISCO-TC.mib");
49
+ store.loadFromFile (mibDir + "CISCO-LWAPP-TC-MIB.mib");
50
+ store.loadFromFile (mibDir + "CISCO-LWAPP-WLAN-MIB.mib");
51
+ store.loadFromFile (mibDir + "ENTITY-MIB.mib");
52
+ store.loadFromFile (mibDir + "CISCO-LWAPP-RF-MIB.mib");
53
+ store.loadFromFile (mibDir + "CISCO-LWAPP-AP-MIB.mib");
54
+ store.loadFromFile (mibDir + "CISCO-LWAPP-DOT11-MIB.mib");
55
+ store.loadFromFile (mibDir + "CISCO-LWAPP-REAP-MIB.mib");
56
+ store.loadFromFile (mibDir + "CISCO-LWAPP-CDP-MIB.mib");
57
+
44
58
  // ifNumber
45
59
  // Scalar type - setScalarValue() and getScalarValue() are the entire API for these
46
60
  mib.setScalarValue ("ifNumber", 5);
package/lib/mib.js CHANGED
@@ -1,18 +1,9 @@
1
1
  var fs = require('fs');
2
2
 
3
3
  var MIB = function (dir) {
4
- return ({
5
- directory: dir ? dir : '',
6
- SymbolBuffer: {},
7
- StringBuffer: '',
8
- Modules: {},
9
- Objects: {},
10
- MACROS: [],
11
- CurrentObject: null,
12
- TempObject: {},
13
- CurrentClause: '',
14
- WaitFor: '',
15
- CharBuffer: {
4
+
5
+ var initializeBuffer = function (buffer) {
6
+ return Object.assign(buffer, {
16
7
  logit: false,
17
8
  lastChar: '',
18
9
  state: '',
@@ -27,11 +18,26 @@ var MIB = function (dir) {
27
18
  inComment: false,
28
19
  inGroup: 0,
29
20
  builder: '',
30
- Table: {},
31
21
  ColumnIndex: 0,
32
22
  RowIndex: 0,
23
+ PreviousRow: 0
24
+ });
25
+ };
26
+
27
+ var newMIB = ({
28
+ directory: dir ? dir : '',
29
+ SymbolBuffer: {},
30
+ StringBuffer: '',
31
+ Modules: {},
32
+ Objects: {},
33
+ MACROS: [],
34
+ CurrentObject: null,
35
+ TempObject: {},
36
+ CurrentClause: '',
37
+ WaitFor: '',
38
+ CharBuffer: {
39
+ Table: {},
33
40
  ModuleName: {},
34
- PreviousRow: 0,
35
41
  Append: function (char) {
36
42
  this.builder += char;
37
43
  },
@@ -45,12 +51,7 @@ var MIB = function (dir) {
45
51
  this.builder.length = 0;
46
52
  if (!this.Table[FileName]) {
47
53
  this.Table[FileName] = [];
48
- }
49
- if (row == 0) {
50
- this.RowIndex = 0;
51
- this.PreviousRow = 0;
52
- }
53
- if (this.PreviousRow < row) {
54
+ } else if (this.PreviousRow < row) {
54
55
  this.RowIndex++;
55
56
  this.ColumnIndex = 0;
56
57
  this.PreviousRow = row;
@@ -60,7 +61,10 @@ var MIB = function (dir) {
60
61
  var C = this.ColumnIndex;
61
62
 
62
63
  if (!this.Table[FileName][R]) {
63
- this.Table[FileName][R] = [];
64
+ this.Table[FileName][R] = Object.defineProperty([], "line", {
65
+ enumerable: false,
66
+ value: row + 1
67
+ });
64
68
  }
65
69
  this.isEqual = false;
66
70
  switch (symbol) {
@@ -128,8 +132,7 @@ var MIB = function (dir) {
128
132
  this.ParseModule(FileName.split('/')[FileName.split('/').length - 1].split('.')[0], fs.readFileSync(FileName).toString());
129
133
  },
130
134
  ParseModule: function (FileName, Contents) {
131
- this.CharBuffer.RowIndex = 0;
132
- this.CharBuffer.ColumnIndex = 0;
135
+ initializeBuffer(this.CharBuffer);
133
136
 
134
137
  var lines = Contents.split('\n');
135
138
  var line = '';
@@ -234,7 +237,7 @@ var MIB = function (dir) {
234
237
  break;
235
238
  case "-":
236
239
  this.CharBuffer.Append(char);
237
- if (this.CharBuffer.lastChar == '-') {
240
+ if (!this.CharBuffer.isString && this.CharBuffer.lastChar == '-') {
238
241
  this.CharBuffer.isComment = true;
239
242
  this.CharBuffer.builder = this.CharBuffer.builder.split('--')[0];
240
243
  this.CharBuffer.Fill(FileName, row, column);
@@ -244,7 +247,7 @@ var MIB = function (dir) {
244
247
  break;
245
248
  case '"':
246
249
  if (this.CharBuffer.isComment && !this.CharBuffer.isString && !this.CharBuffer.inComment) {
247
- //011 = COMMENT
250
+ //011 = COMMENT
248
251
  //IF 011 SET 101
249
252
  this.CharBuffer.isComment = true;
250
253
  this.CharBuffer.isString = false;
@@ -289,18 +292,42 @@ var MIB = function (dir) {
289
292
  for (var FileName in Table) {
290
293
  ModuleName = this.CharBuffer.ModuleName[FileName];
291
294
  this.SymbolBuffer[ModuleName] = [];
292
- for (var r = 0; r < Table[FileName].length; r++) {
293
- for (var c = 0; c < Table[FileName][r].length; c++) {
294
- var symbol = Table[FileName][r][c];
295
+ var foundTheEnd = false;
296
+ var lastGoodDeclaration = [ 'none' ];
297
+ var file = Table[FileName];
298
+ for (var r = 0; r < file.length; r++) {
299
+ var row = file[r];
300
+ for (var c = 0; c < row.length; c++) {
301
+ var symbol = row[c];
302
+ var addSymbol = true;
295
303
  switch (symbol) {
304
+ case 'END':
305
+ foundTheEnd = true;
306
+ break;
307
+ case '::=':
308
+ foundTheEnd = false;
309
+ lastGoodDeclaration = row;
310
+ break;
296
311
  default:
297
- if (symbol.indexOf('--') != 0) {//REMOVE COMMENTS
312
+ if (symbol.indexOf('--') == 0) {//REMOVE COMMENTS
298
313
  //console.log(ModuleName, symbol);
299
- this.SymbolBuffer[ModuleName].push(symbol);
314
+ addSymbol = false;
315
+ } else {
316
+ foundTheEnd = false;
300
317
  }
301
318
  }
319
+ if (addSymbol) {
320
+ this.SymbolBuffer[ModuleName].push(symbol);
321
+ }
302
322
  }
303
323
  }
324
+ if (!foundTheEnd) {
325
+ // Warn that the contents are malformed
326
+ console.warn(
327
+ '[%s]: Incorrect formatting: no END statement found - last good declaration "%s" (line %s)',
328
+ ModuleName, lastGoodDeclaration.join(' '), lastGoodDeclaration.line
329
+ );
330
+ }
304
331
 
305
332
  }
306
333
  this.Compile();
@@ -359,7 +386,7 @@ var MIB = function (dir) {
359
386
  //BUILD OBJECT FROM MACRO TYPE NOTATION
360
387
  var MARCO = this[Symbols[r]];
361
388
  if (!MARCO) {
362
- //HACK IF MARCO IS NOT FOUND
389
+ //HACK IF MARCO IS NOT FOUND
363
390
  //MARCO = {};
364
391
  //return;
365
392
  }
@@ -401,7 +428,7 @@ var MIB = function (dir) {
401
428
  val = val.replace("{", "").replace("}", "").split(",");
402
429
  }
403
430
  }
404
-
431
+
405
432
  switch (key) {
406
433
  case 'SYNTAX':
407
434
  switch (val) {
@@ -727,6 +754,11 @@ var MIB = function (dir) {
727
754
  }
728
755
  }
729
756
  });
757
+
758
+ // Complete buffer setup before returning to caller.
759
+ initializeBuffer(newMIB.CharBuffer);
760
+
761
+ return newMIB;
730
762
  };
731
763
 
732
764
  module.exports = exports = MIB;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "net-snmp",
3
- "version": "3.9.1",
3
+ "version": "3.9.2",
4
4
  "description": "JavaScript implementation of the Simple Network Management Protocol (SNMP)",
5
5
  "main": "index.js",
6
6
  "directories": {