summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/snmp/config.m461
-rw-r--r--ext/snmp/snmp.c10
-rw-r--r--ext/snmp/tests/README2
-rwxr-xr-xext/snmp/tests/bigtest.sh10
-rw-r--r--ext/snmp/tests/bug64159.phpt24
-rw-r--r--ext/snmp/tests/snmpd.conf2
6 files changed, 43 insertions, 66 deletions
diff --git a/ext/snmp/config.m4 b/ext/snmp/config.m4
index ccb7eea9a7..9c0b82f778 100644
--- a/ext/snmp/config.m4
+++ b/ext/snmp/config.m4
@@ -59,67 +59,6 @@ if test "$PHP_SNMP" != "no"; then
$SNMP_SHARED_LIBADD
])
- dnl Check for buggy snmp_snprint_value() (net-snmp BUGid 2027834)
- AC_CACHE_CHECK([for buggy snmp_snprint_value], ac_cv_buggy_snprint_value,[
- save_CFLAGS="$CFLAGS"
- CFLAGS="$CFLAGS -I${SNMP_PREFIX}/include $SNMP_SHARED_LIBADD"
- AC_TRY_RUN( [
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <net-snmp/net-snmp-config.h>
-#include <net-snmp/net-snmp-includes.h>
-
-u_char uname[] = "Linux nex1.php.net 2.6.18-194.32.1.el5 #1 SMP Wed Jan 5 17:53:09 EST 2011 i686";
-
-int main(int argc, char **argv)
-{
- struct variable_list vars;
- char buf1[2048];
- char buf2[sizeof(buf1)];
-
- memset(&(buf1[0]), 0, sizeof(buf1));
- memset(&(buf2[0]), 0, sizeof(buf2));
- memset(&vars, 0, sizeof(vars));
- vars.type = 4;
- vars.val.integer = (long *)&(uname[0]);
- vars.val.string = &(uname[0]);
- vars.val.bitstring = &(uname[0]);
- vars.val.counter64 = (struct counter64 *)&(uname[0]);
- vars.val.floatVal = (float *)&(uname[0]);
- vars.val_len = sizeof(uname),
- vars.name_loc[0] = 1;
- vars.name_loc[1] = 3;
- vars.name_loc[2] = 6;
- vars.name_loc[3] = 1;
- vars.name_loc[4] = 2;
- vars.name_loc[5] = 1;
- vars.name_loc[6] = 1;
- vars.name_loc[7] = 1;
- vars.name = (oid *)&(vars.name_loc);
- vars.name_length = 9;
-
- init_snmp("snmpapp");
-
- netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICK_PRINT, 0);
-
- snprint_value(buf1, (sizeof(uname) + 32), vars.name, vars.name_length, &vars);
- snprint_value(buf2, sizeof(buf2), vars.name, vars.name_length, &vars);
- exit((strncmp(buf1, buf2, sizeof(buf1)) != 0));
-}
- ],[
- ac_cv_buggy_snprint_value=no
- ],[
- ac_cv_buggy_snprint_value=yes
- ],[
- ac_cv_buggy_snprint_value=no
- ])
- CFLAGS="$save_CFLAGS"
- ])
- if test "$ac_cv_buggy_snprint_value" = "yes"; then
- AC_DEFINE(BUGGY_SNMPRINT_VALUE, 1, [ ])
- fi
-
PHP_NEW_EXTENSION(snmp, snmp.c, $ext_shared)
PHP_SUBST(SNMP_SHARED_LIBADD)
fi
diff --git a/ext/snmp/snmp.c b/ext/snmp/snmp.c
index 9d854ec7fe..c97692822b 100644
--- a/ext/snmp/snmp.c
+++ b/ext/snmp/snmp.c
@@ -551,11 +551,7 @@ static void php_snmp_error(zval *object, const char *docref TSRMLS_DC, int type,
static void php_snmp_getvalue(struct variable_list *vars, zval *snmpval TSRMLS_DC, int valueretrieval)
{
zval *val;
-#ifdef BUGGY_SNMPRINT_VALUE
- char sbuf[2048];
-#else
- char sbuf[64];
-#endif
+ char sbuf[512];
char *buf = &(sbuf[0]);
char *dbuf = (char *)NULL;
int buflen = sizeof(sbuf) - 1;
@@ -569,6 +565,10 @@ static void php_snmp_getvalue(struct variable_list *vars, zval *snmpval TSRMLS_D
while ((valueretrieval & SNMP_VALUE_PLAIN) == 0) {
*buf = '\0';
if (snprint_value(buf, buflen, vars->name, vars->name_length, vars) == -1) {
+ if (val_len > 512*1024) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "snprint_value() asks for a buffer more than 512k, Net-SNMP bug?");
+ break;
+ }
/* buffer is not long enough to hold full output, double it */
val_len *= 2;
} else {
diff --git a/ext/snmp/tests/README b/ext/snmp/tests/README
index 819a50d8a2..0db1a4f82b 100644
--- a/ext/snmp/tests/README
+++ b/ext/snmp/tests/README
@@ -35,6 +35,8 @@ On Linux/FreeBSD
Before launching daemon make sure that there is no file /var/net-snmp/snmpd.conf
Delete it if exists. Ingoring to to so will fail SNMPv3 tests.
+- Place bigtest.sh near snmpd.conf, tune path to it in snmpd.conf
+
- Launch snmpd (service snmpd start or /etc/init.d/snmpd start).
Alternatively you can start snmpd daemon using following command line:
sudo snmpd -C -c ./snmpd.conf -f -Le
diff --git a/ext/snmp/tests/bigtest.sh b/ext/snmp/tests/bigtest.sh
new file mode 100755
index 0000000000..d0d8be783b
--- /dev/null
+++ b/ext/snmp/tests/bigtest.sh
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+Q="";
+i=0;
+while [ $i -lt 32 ]; do
+ Q="${Q}\3\2\4\11\22\13\14\15\16\17\20\21\22\23\24\25\26\27";
+ i=$((i+1));
+done
+
+printf "${Q}"
diff --git a/ext/snmp/tests/bug64159.phpt b/ext/snmp/tests/bug64159.phpt
new file mode 100644
index 0000000000..51b1599529
--- /dev/null
+++ b/ext/snmp/tests/bug64159.phpt
@@ -0,0 +1,24 @@
+--TEST--
+Bug #64159: Truncated snmpget
+--CREDITS--
+Boris Lytochkin
+--SKIPIF--
+<?php
+require_once(dirname(__FILE__).'/skipif.inc');
+?>
+--ENV--
+MIBS=noneXistent
+--FILE--
+<?php
+require_once(dirname(__FILE__).'/snmp_include.inc');
+
+snmp_set_quick_print(false);
+snmp_set_valueretrieval(SNMP_VALUE_LIBRARY);
+
+var_dump(("ab8283f948419b2d24d22f44a80b17d3" === md5(snmpget($hostname, $community, '.1.3.6.1.4.1.2021.8.1.101.2'))));
+
+?>
+--EXPECTF--
+MIB search path: %s
+Cannot find module (noneXistent): At line %d in (%s)
+bool(true)
diff --git a/ext/snmp/tests/snmpd.conf b/ext/snmp/tests/snmpd.conf
index 3e91372944..5297d0b9ea 100644
--- a/ext/snmp/tests/snmpd.conf
+++ b/ext/snmp/tests/snmpd.conf
@@ -23,3 +23,5 @@ createUser adminMD5DES MD5 test1234 DES test1234
createUser noAuthUser
authuser read noAuthUser noauth
+
+exec HexTest /bin/sh /etc/snmp/bigtest.sh