Grokbase Groups PHP php-cvs May 2013
FAQ
Commit: e36adfe94a663bc1eeb5d9d378dc80883de179db
Author: Boris Lytochkin <lytboris@php.net> Fri, 3 May 2013 15:35:09 +0400
Parents: a39282b64dad04a047f0ff8c230a5a64ad417a2f
Branches: PHP-5.4 PHP-5.5 master

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

Log:
Fixed bug #64159 (Truncated snmpget)

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

Changed paths:
M NEWS
M ext/snmp/snmp.c


Diff:
diff --git a/NEWS b/NEWS
index b6dc09c..dba1508 100644
--- a/NEWS
+++ b/NEWS
@@ -14,6 +14,7 @@ PHP NEWS
- SNMP:
. Fixed bug #64765 (Some IPv6 addresses get interpreted wrong).
(Boris Lytochkin)
+ . Fixed bug #64159 (Truncated snmpget). (Boris Lytochkin)

?? ??? 2013, PHP 5.4.15
- Core:
diff --git a/ext/snmp/snmp.c b/ext/snmp/snmp.c
index fad5d05..9d854ec 100644
--- a/ext/snmp/snmp.c
+++ b/ext/snmp/snmp.c
@@ -561,25 +561,50 @@ static void php_snmp_getvalue(struct variable_list *vars, zval *snmpval TSRMLS_D
int buflen = sizeof(sbuf) - 1;
int val_len = vars->val_len;

- if ((valueretrieval & SNMP_VALUE_PLAIN) == 0) {
- val_len += 32; /* snprint_value will add type info into value, make some space for it */
+ /* use emalloc() for large values, use static array otherwize */
+
+ /* There is no way to know the size of buffer snprint_value() needs in order to print a value there.
+ * So we are forced to probe it
+ */
+ while ((valueretrieval & SNMP_VALUE_PLAIN) == 0) {
+ *buf = '\0';
+ if (snprint_value(buf, buflen, vars->name, vars->name_length, vars) == -1) {
+ /* buffer is not long enough to hold full output, double it */
+ val_len *= 2;
+ } else {
+ break;
+ }
+
+ if (buf == dbuf) {
+ dbuf = (char *)erealloc(dbuf, val_len + 1);
+ } else {
+ dbuf = (char *)emalloc(val_len + 1);
+ }
+
+ if (!dbuf) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "emalloc() failed: %s, fallback to static buffer", strerror(errno));
+ buf = &(sbuf[0]);
+ buflen = sizeof(sbuf) - 1;
+ break;
+ }
+
+ buf = dbuf;
+ buflen = val_len;
}

- /* use emalloc() for large values, use static array otherwize */
- if(val_len > buflen){
+ if((valueretrieval & SNMP_VALUE_PLAIN) && val_len > buflen){
if ((dbuf = (char *)emalloc(val_len + 1))) {
buf = dbuf;
buflen = val_len;
} else {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "emalloc() failed: %s, fallback to static array", strerror(errno));
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "emalloc() failed: %s, fallback to static buffer", strerror(errno));
}
}

- *buf = 0;
-
MAKE_STD_ZVAL(val);

if (valueretrieval & SNMP_VALUE_PLAIN) {
+ *buf = 0;
switch (vars->type) {
case ASN_BIT_STR: /* 0x03, asn1.h */
ZVAL_STRINGL(val, (char *)vars->val.bitstring, vars->val_len, 1);
@@ -652,7 +677,7 @@ static void php_snmp_getvalue(struct variable_list *vars, zval *snmpval TSRMLS_D
break;
}
} else /* use Net-SNMP value translation */ {
- snprint_value(buf, buflen, vars->name, vars->name_length, vars);
+ /* we have desired string in buffer, just use it */
ZVAL_STRING(val, buf, 1);
}

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 1 | next ›
Discussion Overview
groupphp-cvs @
categoriesphp
postedMay 3, '13 at 12:08p
activeMay 3, '13 at 12:08p
posts1
users1
websitephp.net

1 user in discussion

Boris Lytochkin: 1 post

People

Translate

site design / logo © 2019 Grokbase