Skip to content

Commit 03e28b6

Browse files
crazyscientistkain88-despt29
authored andcommitted
Fix segfaults when varbind cannot be constructed
For multiple reasons, `varbind` can be a null pointer, which causes segmentation faults. With this change, the value is checked and the segmentation fault avoided. Co-authored-by: kain88-de <[email protected]> Co-authored-by: spt29 <[email protected]>
1 parent bda9af7 commit 03e28b6

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

python/netsnmp/client_intf.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1520,6 +1520,10 @@ netsnmp_get_or_getnext(PyObject *self, PyObject *args, int pdu_type,
15201520
continue;
15211521

15221522
varbind = PySequence_GetItem(varlist, varlist_ind);
1523+
if (varbind == NULL) {
1524+
/* PySequence_GetItem failed - break to avoid NULL deref in build_python_varbind */
1525+
break;
1526+
}
15231527
type = build_python_varbind(varbind, vars, varlist_ind, sprintval_flag,
15241528
&len, &str_buf, getlabel_flag);
15251529
if (type != TYPE_OTHER) {
@@ -1828,6 +1832,9 @@ netsnmp_walk(PyObject *self, PyObject *args)
18281832
}
18291833

18301834
varbind = py_netsnmp_construct_varbind();
1835+
if (varbind == NULL)
1836+
break;
1837+
18311838
if (varbind && build_python_varbind(varbind, vars, varlist_ind,
18321839
sprintval_flag, &len, &str_buf, getlabel_flag) !=
18331840
TYPE_OTHER) {
@@ -2051,6 +2058,9 @@ netsnmp_getbulk(PyObject *self, PyObject *args)
20512058
vars = vars->next_variable, varbind_ind++) {
20522059

20532060
varbind = py_netsnmp_construct_varbind();
2061+
if (varbind == NULL)
2062+
break;
2063+
20542064
if (varbind && build_python_varbind(varbind, vars, varbind_ind,
20552065
sprintval_flag, &len, &str_buf, getlabel_flag) != TYPE_OTHER) {
20562066
const int hex = is_hex(str_buf, len);

0 commit comments

Comments
 (0)