9a6c41
1064338 - various net-snmp-python return code errors
9a6c41
 
9a6c41
commit 71a31dabc05e4e86ba14deff427a6911c167e713
9a6c41
Author: Wes Hardaker <hardaker@users.sourceforge.net>
9a6c41
Date:   Fri Jul 30 13:00:49 2010 +0000
9a6c41
9a6c41
    CHANGES: python: patch 3035578: from sws: keep error codes up to date
9a6c41
9a6c41
    git-svn-id: file:///home/hardaker/lib/sf-bkups/net-snmp-convert-svnrepo/trunk@19268 06827809-a52a-0410-b366-d66718629ded
9a6c41
9a6c41
9a6c41
commit 7e1cae42bd79a0cdfb70521558a0dedc5aa0c42d
9a6c41
Author: Dave Shield <dts12@users.sourceforge.net>
9a6c41
Date:   Thu Apr 14 21:31:09 2011 +0000
9a6c41
9a6c41
     CHANGES: python: PATCHES: 3185085: Fix segfault on 64-bit systems
9a6c41
     git-svn-id: file:///home/hardaker/lib/sf-bkups/net-snmp-convert-svnrepo/trunk@20180 06827809-a52a-0410-b366-d66718629ded
9a6c41
9a6c41
commit 9a2bfc8f95d6e926dcbf16ff44b53b27e38c8437
9a6c41
Author: Jan Safranek <jsafranek@users.sourceforge.net>
9a6c41
Date:   Mon Jul 1 13:54:38 2013 +0200
9a6c41
9a6c41
    CHANGES: python: Fixed returning of empty strings.
9a6c41
    Varbind type (SNMP_NOSUCHOBJECT etc.) should be used to detect errors instead of length of the variable - it can be empty string.
9a6c41
9a6c41
commit 408cc9732c346111fc1fda23e136d60883cdb7e4
9a6c41
Author: Jan Safranek <jsafranek@users.sourceforge.net>
9a6c41
Date:   Mon Jul 1 14:25:41 2013 +0200
9a6c41
9a6c41
    CHANGES: python: correctly report error when parsing malformed OID.
9a6c41
9a6c41
diff -up net-snmp-5.7.2/python/netsnmp/client_intf.c.test net-snmp-5.7.2/python/netsnmp/client_intf.c
9a6c41
--- net-snmp-5.7.2/python/netsnmp/client_intf.c.test	2014-02-13 09:34:37.456480927 +0100
9a6c41
+++ net-snmp-5.7.2/python/netsnmp/client_intf.c	2014-02-13 09:51:22.475642391 +0100
9a6c41
@@ -658,7 +658,10 @@ int    best_guess;
9a6c41
 	newname_len = MAX_OID_LEN;
9a6c41
 	if (read_objid(tag, newname, &newname_len)) {	/* long name */
9a6c41
 	  rtp = tp = get_tree(newname, newname_len, get_tree_head());
9a6c41
-	}
9a6c41
+	} else {
9a6c41
+	  /* failed to parse the OID */
9a6c41
+	  newname_len = 0;
9a6c41
+	}
9a6c41
       }
9a6c41
       else {
9a6c41
 	rtp = tp = get_tree(newname, newname_len, get_tree_head());
9a6c41
@@ -885,6 +887,15 @@ int *err_ind;
9a6c41
        goto done;
9a6c41
    }
9a6c41
 
9a6c41
+   tmp_err_str = calloc(1, STR_BUF_SIZE);
9a6c41
+   if (tmp_err_str == NULL) {
9a6c41
+       *err_num = errno;
9a6c41
+       *err_ind = SNMPERR_MALLOC;
9a6c41
+       status = SNMPERR_MALLOC;
9a6c41
+       strncpy(err_str, snmp_api_errstring(*err_ind), STR_BUF_SIZE - 1);
9a6c41
+       goto done;
9a6c41
+   }
9a6c41
+
9a6c41
 retry:
9a6c41
 
9a6c41
    Py_BEGIN_ALLOW_THREADS
9a6c41
@@ -1589,10 +1600,16 @@ netsnmp_get(PyObject *self, PyObject *ar
9a6c41
 	py_netsnmp_attr_set_string(varbind, "val", (char *) str_buf, len);
9a6c41
 
9a6c41
 	/* save in return tuple as well */
9a6c41
-	PyTuple_SetItem(val_tuple, varlist_ind, 
9a6c41
-			(len ? Py_BuildValue("s#", str_buf, len) :
9a6c41
-			 Py_BuildValue("")));
9a6c41
-
9a6c41
+	if ((type == SNMP_ENDOFMIBVIEW) ||
9a6c41
+			(type == SNMP_NOSUCHOBJECT) ||
9a6c41
+			(type == SNMP_NOSUCHINSTANCE)) {
9a6c41
+		/* Translate error to None */
9a6c41
+		PyTuple_SetItem(val_tuple, varlist_ind, 
9a6c41
+			Py_BuildValue(""));
9a6c41
+	} else {
9a6c41
+		PyTuple_SetItem(val_tuple, varlist_ind,
9a6c41
+			Py_BuildValue("s#", str_buf, len));
9a6c41
+	}
9a6c41
 	Py_DECREF(varbind);
9a6c41
       } else {
9a6c41
 	printf("netsnmp_get: bad varbind (%d)\n", varlist_ind);
9a6c41
@@ -1801,10 +1818,16 @@ netsnmp_getnext(PyObject *self, PyObject
9a6c41
 	py_netsnmp_attr_set_string(varbind, "val", (char *) str_buf, len);
9a6c41
 
9a6c41
 	/* save in return tuple as well */
9a6c41
-	PyTuple_SetItem(val_tuple, varlist_ind, 
9a6c41
-			(len ? Py_BuildValue("s#", str_buf, len) :
9a6c41
-			 Py_BuildValue("")));
9a6c41
-
9a6c41
+	if ((type == SNMP_ENDOFMIBVIEW) ||
9a6c41
+			(type == SNMP_NOSUCHOBJECT) ||
9a6c41
+			(type == SNMP_NOSUCHINSTANCE)) {
9a6c41
+		/* Translate error to None */
9a6c41
+		PyTuple_SetItem(val_tuple, varlist_ind, 
9a6c41
+			Py_BuildValue(""));
9a6c41
+	} else {
9a6c41
+		PyTuple_SetItem(val_tuple, varlist_ind,
9a6c41
+			Py_BuildValue("s#", str_buf, len));
9a6c41
+	}
9a6c41
 	Py_DECREF(varbind);
9a6c41
       } else {
9a6c41
 	printf("netsnmp_getnext: bad varbind (%d)\n", varlist_ind);