Merge branch 'PHP-5.5'

* PHP-5.5:
  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
  cut PHP_VERSION_ID - we know API version now
This commit is contained in:
Boris Lytochkin 2013-05-03 23:22:27 +04:00
commit 7f5a4cd70a
6 changed files with 43 additions and 135 deletions

View File

@ -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

View File

@ -80,14 +80,6 @@
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#if PHP_VERSION_ID < 50300
#define Z_ADDREF_P(pz) pz->refcount++
#define Z_ISREF_PP(oid) (PZVAL_IS_REF(*(oid)))
#define Z_REFCOUNT_P(pz) pz->refcount
#define Z_SET_REFCOUNT_P(pz, rc) pz->refcount = rc
#define zend_parse_parameters_none() zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "")
#endif
/* For net-snmp prior to 5.4 */
#ifndef HAVE_SHUTDOWN_SNMP_LOGGING
extern netsnmp_log_handler *logh_head;
@ -497,9 +489,6 @@ static void php_snmp_object_free_storage(void *object TSRMLS_DC)
static zend_object_value php_snmp_object_new(zend_class_entry *class_type TSRMLS_DC) /* {{{ */
{
#if PHP_VERSION_ID < 50399
zval *tmp;
#endif
zend_object_value retval;
php_snmp_object *intern;
@ -508,11 +497,7 @@ static zend_object_value php_snmp_object_new(zend_class_entry *class_type TSRMLS
memset(&intern->zo, 0, sizeof(php_snmp_object));
zend_object_std_init(&intern->zo, class_type TSRMLS_CC);
#if PHP_VERSION_ID < 50399
zend_hash_copy(intern->zo.properties, &class_type->default_properties, (copy_ctor_func_t) zval_add_ref,(void *) &tmp, sizeof(zval *));
#else
object_properties_init(&intern->zo, class_type);
#endif
retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, (zend_objects_free_object_storage_t) php_snmp_object_free_storage, NULL TSRMLS_CC);
retval.handlers = (zend_object_handlers *) &php_snmp_object_handlers;
@ -566,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;
@ -584,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 {
@ -1801,11 +1786,7 @@ PHP_FUNCTION(snmp_read_mib)
char *filename;
int filename_len;
#if PHP_VERSION_ID < 50399
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) {
#else
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &filename, &filename_len) == FAILURE) {
#endif
RETURN_FALSE;
}
@ -1830,31 +1811,17 @@ PHP_METHOD(snmp, __construct)
long retries = SNMP_DEFAULT_RETRIES;
long version = SNMP_DEFAULT_VERSION;
int argc = ZEND_NUM_ARGS();
#if PHP_VERSION_ID > 50300
zend_error_handling error_handling;
#endif
snmp_object = (php_snmp_object *)zend_object_store_get_object(object TSRMLS_CC);
#if PHP_VERSION_ID > 50300
zend_replace_error_handling(EH_THROW, NULL, &error_handling TSRMLS_CC);
#else
php_set_error_handling(EH_THROW, zend_exception_get_default(TSRMLS_C) TSRMLS_CC);
#endif
if (zend_parse_parameters(argc TSRMLS_CC, "lss|ll", &version, &a1, &a1_len, &a2, &a2_len, &timeout, &retries) == FAILURE) {
#if PHP_VERSION_ID > 50300
zend_restore_error_handling(&error_handling TSRMLS_CC);
#else
php_std_error_handling();
#endif
return;
}
#if PHP_VERSION_ID > 50300
zend_restore_error_handling(&error_handling TSRMLS_CC);
#else
php_std_error_handling();
#endif
switch(version) {
case SNMP_VERSION_1:
@ -2002,11 +1969,7 @@ void php_snmp_add_property(HashTable *h, const char *name, size_t name_length, p
/* {{{ php_snmp_read_property(zval *object, zval *member, int type[, const zend_literal *key])
Generic object property reader */
#if PHP_VERSION_ID < 50399
zval *php_snmp_read_property(zval *object, zval *member, int type TSRMLS_DC)
#else
zval *php_snmp_read_property(zval *object, zval *member, int type, const zend_literal *key TSRMLS_DC)
#endif
{
zval tmp_member;
zval *retval;
@ -2036,11 +1999,7 @@ zval *php_snmp_read_property(zval *object, zval *member, int type, const zend_li
}
} else {
zend_object_handlers * std_hnd = zend_get_std_object_handlers();
#if PHP_VERSION_ID < 50399
retval = std_hnd->read_property(object, member, type TSRMLS_CC);
#else
retval = std_hnd->read_property(object, member, type, key TSRMLS_CC);
#endif
}
if (member == &tmp_member) {
@ -2052,11 +2011,7 @@ zval *php_snmp_read_property(zval *object, zval *member, int type, const zend_li
/* {{{ php_snmp_write_property(zval *object, zval *member, zval *value[, const zend_literal *key])
Generic object property writer */
#if PHP_VERSION_ID < 50399
void php_snmp_write_property(zval *object, zval *member, zval *value TSRMLS_DC)
#else
void php_snmp_write_property(zval *object, zval *member, zval *value, const zend_literal *key TSRMLS_DC)
#endif
{
zval tmp_member;
php_snmp_object *obj;
@ -2083,11 +2038,7 @@ void php_snmp_write_property(zval *object, zval *member, zval *value, const zend
}
} else {
zend_object_handlers * std_hnd = zend_get_std_object_handlers();
#if PHP_VERSION_ID < 50399
std_hnd->write_property(object, member, value TSRMLS_CC);
#else
std_hnd->write_property(object, member, value, key TSRMLS_CC);
#endif
}
if (member == &tmp_member) {
@ -2098,11 +2049,7 @@ void php_snmp_write_property(zval *object, zval *member, zval *value, const zend
/* {{{ php_snmp_has_property(zval *object, zval *member, int has_set_exists[, const zend_literal *key])
Generic object property checker */
#if PHP_VERSION_ID < 50399
static int php_snmp_has_property(zval *object, zval *member, int has_set_exists TSRMLS_DC)
#else
static int php_snmp_has_property(zval *object, zval *member, int has_set_exists, const zend_literal *key TSRMLS_DC)
#endif
{
php_snmp_prop_handler *hnd;
int ret = 0;
@ -2113,11 +2060,7 @@ static int php_snmp_has_property(zval *object, zval *member, int has_set_exists,
ret = 1;
break;
case 0: {
#if PHP_VERSION_ID < 50399
zval *value = php_snmp_read_property(object, member, BP_VAR_IS TSRMLS_CC);
#else
zval *value = php_snmp_read_property(object, member, BP_VAR_IS, key TSRMLS_CC);
#endif
if (value != EG(uninitialized_zval_ptr)) {
ret = Z_TYPE_P(value) != IS_NULL? 1:0;
/* refcount is 0 */
@ -2127,11 +2070,7 @@ static int php_snmp_has_property(zval *object, zval *member, int has_set_exists,
break;
}
default: {
#if PHP_VERSION_ID < 50399
zval *value = php_snmp_read_property(object, member, BP_VAR_IS TSRMLS_CC);
#else
zval *value = php_snmp_read_property(object, member, BP_VAR_IS, key TSRMLS_CC);
#endif
if (value != EG(uninitialized_zval_ptr)) {
convert_to_boolean(value);
ret = Z_BVAL_P(value)? 1:0;
@ -2144,11 +2083,7 @@ static int php_snmp_has_property(zval *object, zval *member, int has_set_exists,
}
} else {
zend_object_handlers * std_hnd = zend_get_std_object_handlers();
#if PHP_VERSION_ID < 50399
ret = std_hnd->has_property(object, member, has_set_exists TSRMLS_CC);
#else
ret = std_hnd->has_property(object, member, has_set_exists, key TSRMLS_CC);
#endif
}
return ret;
}
@ -2168,11 +2103,7 @@ static HashTable *php_snmp_get_properties(zval *object TSRMLS_DC)
ulong num_key;
obj = (php_snmp_object *)zend_objects_get_address(object TSRMLS_CC);
#if PHP_VERSION_ID < 50399
props = obj->zo.properties;
#else
props = zend_std_get_properties(object TSRMLS_CC);
#endif
zend_hash_internal_pointer_reset_ex(&php_snmp_properties, &pos);

View File

@ -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

10
ext/snmp/tests/bigtest.sh Executable file
View File

@ -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}"

View File

@ -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)

View File

@ -23,3 +23,5 @@ createUser adminMD5DES MD5 test1234 DES test1234
createUser noAuthUser
authuser read noAuthUser noauth
exec HexTest /bin/sh /etc/snmp/bigtest.sh