summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIlya Etingof <etingof@gmail.com>2018-08-05 09:52:42 +0200
committerGitHub <noreply@github.com>2018-08-05 09:52:42 +0200
commitee321e04796d0a6874ae85385a5df00aa76f8066 (patch)
tree98e4dc857561db43f8a588821144e121490026c0
parent7abfa51a9993e3a79404990f844d655b3bd3ba26 (diff)
downloadpysnmp-git-ee321e04796d0a6874ae85385a5df00aa76f8066.tar.gz
Fix out-of-scope OID leak in hlapi table (#172)
Fixed out-of-scope OIDs possibly leaking at the end of SNMP table at hlapi `nextCmd` and `bulkCmd` calls when `lexicographicMode = False`.
-rw-r--r--CHANGES.txt2
-rw-r--r--pysnmp/hlapi/asyncore/sync/cmdgen.py40
2 files changed, 32 insertions, 10 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index ecdd5587..009f6f34 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -9,6 +9,8 @@ Revision 4.4.5, released 2018-04-XX
- Fixed `Bits` class initialization when enumeration values are given
- Fixed crash caused by incoming SNMPv3 message requesting SNMPv1/v2c
security model
+- Fixed out-of-scope OIDs leaking at the end of SNMP table at hlapi
+ `nextCmd` and `bulkCmd` calls when `lexicographicMode = False`
Revision 4.4.4, released 2018-01-03
-----------------------------------
diff --git a/pysnmp/hlapi/asyncore/sync/cmdgen.py b/pysnmp/hlapi/asyncore/sync/cmdgen.py
index fb0723f4..3868ac66 100644
--- a/pysnmp/hlapi/asyncore/sync/cmdgen.py
+++ b/pysnmp/hlapi/asyncore/sync/cmdgen.py
@@ -351,6 +351,8 @@ def nextCmd(snmpEngine, authData, transportTarget, contextData,
totalRows = totalCalls = 0
while True:
+ previousVarBinds = varBinds
+
if varBinds:
cmdgen.nextCmd(snmpEngine, authData, transportTarget, contextData,
*[(x[0], Null('')) for x in varBinds],
@@ -378,13 +380,22 @@ def nextCmd(snmpEngine, authData, transportTarget, contextData,
yield (errorIndication, errorStatus, errorIndex, varBinds)
return
else:
+ stopFlag = True
+
varBinds = cbCtx['varBindTable'] and cbCtx['varBindTable'][0]
- for idx, varBind in enumerate(varBinds):
+
+ for col, varBind in enumerate(varBinds):
name, val = varBind
- if not isinstance(val, Null):
- if lexicographicMode or initialVars[idx].isPrefixOf(name):
- break
- else:
+ if isinstance(val, Null):
+ varBinds[col] = previousVarBinds[col][0], endOfMibView
+
+ if not lexicographicMode and not initialVars[col].isPrefixOf(name):
+ varBinds[col] = previousVarBinds[col][0], endOfMibView
+
+ if stopFlag and varBinds[col][1] is not endOfMibView:
+ stopFlag = False
+
+ if stopFlag:
return
totalRows += 1
@@ -545,6 +556,8 @@ def bulkCmd(snmpEngine, authData, transportTarget, contextData,
if maxRows and totalRows < maxRows:
maxRepetitions = min(maxRepetitions, maxRows - totalRows)
+ previousVarBinds = varBinds
+
cmdgen.bulkCmd(snmpEngine, authData, transportTarget, contextData,
nonRepeaters, maxRepetitions,
*[(x[0], Null('')) for x in varBinds],
@@ -583,14 +596,17 @@ def bulkCmd(snmpEngine, authData, transportTarget, contextData,
break
for col in range(len(varBindTable[row])):
name, val = varBindTable[row][col]
+ if row:
+ previousVarBinds = varBindTable[row - 1]
if nullVarBinds[col]:
- varBindTable[row][col] = name, endOfMibView
+ varBindTable[row][col] = previousVarBinds[col][0], endOfMibView
continue
stopFlag = False
if isinstance(val, Null):
+ varBindTable[row][col] = previousVarBinds[col][0], endOfMibView
nullVarBinds[col] = True
- elif not lexicographicMode and not initialVars[col].isPrefixOf(name):
- varBindTable[row][col] = name, endOfMibView
+ if not lexicographicMode and not initialVars[col].isPrefixOf(name):
+ varBindTable[row][col] = previousVarBinds[col][0], endOfMibView
nullVarBinds[col] = True
if stopFlag:
varBindTable = row and varBindTable[:row - 1] or []
@@ -607,9 +623,13 @@ def bulkCmd(snmpEngine, authData, transportTarget, contextData,
if maxCalls and totalCalls >= maxCalls:
stopFlag = True
- for varBinds in varBindTable:
- initialVarBinds = (yield errorIndication, errorStatus, errorIndex, varBinds)
+ varBinds = varBindTable and varBindTable[-1] or []
+
+ for varBindRow in varBindTable:
+ initialVarBinds = (yield errorIndication, errorStatus, errorIndex, varBindRow)
if initialVarBinds:
varBinds = initialVarBinds
initialVars = [x[0] for x in vbProcessor.makeVarBinds(snmpEngine, varBinds)]
+ nullVarBinds = [False] * len(initialVars)
+