Blob Blame History Raw
1064338 - various net-snmp-python return code errors
 
commit 71a31dabc05e4e86ba14deff427a6911c167e713
Author: Wes Hardaker <hardaker@users.sourceforge.net>
Date:   Fri Jul 30 13:00:49 2010 +0000

    CHANGES: python: patch 3035578: from sws: keep error codes up to date

    git-svn-id: file:///home/hardaker/lib/sf-bkups/net-snmp-convert-svnrepo/trunk@19268 06827809-a52a-0410-b366-d66718629ded


commit 7e1cae42bd79a0cdfb70521558a0dedc5aa0c42d
Author: Dave Shield <dts12@users.sourceforge.net>
Date:   Thu Apr 14 21:31:09 2011 +0000

     CHANGES: python: PATCHES: 3185085: Fix segfault on 64-bit systems
     git-svn-id: file:///home/hardaker/lib/sf-bkups/net-snmp-convert-svnrepo/trunk@20180 06827809-a52a-0410-b366-d66718629ded

commit 9a2bfc8f95d6e926dcbf16ff44b53b27e38c8437
Author: Jan Safranek <jsafranek@users.sourceforge.net>
Date:   Mon Jul 1 13:54:38 2013 +0200

    CHANGES: python: Fixed returning of empty strings.
    Varbind type (SNMP_NOSUCHOBJECT etc.) should be used to detect errors instead of length of the variable - it can be empty string.

commit 408cc9732c346111fc1fda23e136d60883cdb7e4
Author: Jan Safranek <jsafranek@users.sourceforge.net>
Date:   Mon Jul 1 14:25:41 2013 +0200

    CHANGES: python: correctly report error when parsing malformed OID.

diff -up net-snmp-5.7.2/python/netsnmp/client_intf.c.test net-snmp-5.7.2/python/netsnmp/client_intf.c
--- net-snmp-5.7.2/python/netsnmp/client_intf.c.test	2014-02-13 09:34:37.456480927 +0100
+++ net-snmp-5.7.2/python/netsnmp/client_intf.c	2014-02-13 09:51:22.475642391 +0100
@@ -658,7 +658,10 @@ int    best_guess;
 	newname_len = MAX_OID_LEN;
 	if (read_objid(tag, newname, &newname_len)) {	/* long name */
 	  rtp = tp = get_tree(newname, newname_len, get_tree_head());
-	}
+	} else {
+	  /* failed to parse the OID */
+	  newname_len = 0;
+	}
       }
       else {
 	rtp = tp = get_tree(newname, newname_len, get_tree_head());
@@ -885,6 +887,15 @@ int *err_ind;
        goto done;
    }
 
+   tmp_err_str = calloc(1, STR_BUF_SIZE);
+   if (tmp_err_str == NULL) {
+       *err_num = errno;
+       *err_ind = SNMPERR_MALLOC;
+       status = SNMPERR_MALLOC;
+       strncpy(err_str, snmp_api_errstring(*err_ind), STR_BUF_SIZE - 1);
+       goto done;
+   }
+
 retry:
 
    Py_BEGIN_ALLOW_THREADS
@@ -1589,10 +1600,16 @@ netsnmp_get(PyObject *self, PyObject *ar
 	py_netsnmp_attr_set_string(varbind, "val", (char *) str_buf, len);
 
 	/* save in return tuple as well */
-	PyTuple_SetItem(val_tuple, varlist_ind, 
-			(len ? Py_BuildValue("s#", str_buf, len) :
-			 Py_BuildValue("")));
-
+	if ((type == SNMP_ENDOFMIBVIEW) ||
+			(type == SNMP_NOSUCHOBJECT) ||
+			(type == SNMP_NOSUCHINSTANCE)) {
+		/* Translate error to None */
+		PyTuple_SetItem(val_tuple, varlist_ind, 
+			Py_BuildValue(""));
+	} else {
+		PyTuple_SetItem(val_tuple, varlist_ind,
+			Py_BuildValue("s#", str_buf, len));
+	}
 	Py_DECREF(varbind);
       } else {
 	printf("netsnmp_get: bad varbind (%d)\n", varlist_ind);
@@ -1801,10 +1818,16 @@ netsnmp_getnext(PyObject *self, PyObject
 	py_netsnmp_attr_set_string(varbind, "val", (char *) str_buf, len);
 
 	/* save in return tuple as well */
-	PyTuple_SetItem(val_tuple, varlist_ind, 
-			(len ? Py_BuildValue("s#", str_buf, len) :
-			 Py_BuildValue("")));
-
+	if ((type == SNMP_ENDOFMIBVIEW) ||
+			(type == SNMP_NOSUCHOBJECT) ||
+			(type == SNMP_NOSUCHINSTANCE)) {
+		/* Translate error to None */
+		PyTuple_SetItem(val_tuple, varlist_ind, 
+			Py_BuildValue(""));
+	} else {
+		PyTuple_SetItem(val_tuple, varlist_ind,
+			Py_BuildValue("s#", str_buf, len));
+	}
 	Py_DECREF(varbind);
       } else {
 	printf("netsnmp_getnext: bad varbind (%d)\n", varlist_ind);