Commit:    c34274acb8dedda6cbb05a54fa8a2bd0b4533be1
Author:    Boris Lytochkin <lytbo...@php.net>         Fri, 3 May 2013 23:06:34 
+0400
Parents:   3a413f216abb1ce6564d4b8bd493664c32eb928a
Branches:  PHP-5.4 PHP-5.5 master

Link:       
http://git.php.net/?p=php-src.git;a=commitdiff;h=c34274acb8dedda6cbb05a54fa8a2bd0b4533be1

Log:
re-work walkaround for net-snmp BUGid 2027834, no need to detect it anymore
add test for Bug #64159
bump default buffer size for values(32->512): do not reallocate buffers in 99% 
cases

Bugs:
https://bugs.php.net/64159

Changed paths:
  M  ext/snmp/config.m4
  M  ext/snmp/snmp.c
  M  ext/snmp/tests/README
  A  ext/snmp/tests/bigtest.sh
  A  ext/snmp/tests/bug64159.phpt
  M  ext/snmp/tests/snmpd.conf


Diff:
diff --git a/ext/snmp/config.m4 b/ext/snmp/config.m4
index ccb7eea..9c0b82f 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 9d854ec..c976928 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 819a50d..0db1a4f 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 0000000..d0d8be7
--- /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 0000000..51b1599
--- /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 3e91372..5297d0b 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


--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to