@@ -832,7 +832,7 @@ static bool php_snmp_parse_oid(
832
832
/* {{{ netsnmp_session_init
833
833
allocates memory for session and session->peername, caller should free it manually using session_free() and efree()
834
834
*/
835
- static bool netsnmp_session_init (php_snmp_session * * session_p , int version , zend_string * hostname , zend_string * community , zend_long timeout , zend_long retries )
835
+ static bool netsnmp_session_init (php_snmp_session * * session_p , int version , zend_string * hostname , zend_string * community , zend_long timeout , zend_long retries , int timeout_argument_offset )
836
836
{
837
837
php_snmp_session * session ;
838
838
char * pptr , * host_ptr ;
@@ -843,21 +843,41 @@ static bool netsnmp_session_init(php_snmp_session **session_p, int version, zend
843
843
844
844
* session_p = 0 ;
845
845
846
+ ZEND_ASSERT (hostname != NULL );
847
+ ZEND_ASSERT (community != NULL );
848
+
849
+ if (zend_str_has_nul_byte (hostname )) {
850
+ zend_argument_value_error (2 , "must not contain any null bytes" );
851
+ return false;
852
+ }
853
+
846
854
if (ZSTR_LEN (hostname ) >= MAX_NAME_LEN ) {
847
- zend_value_error ( "hostname length must be lower than %d" , MAX_NAME_LEN );
855
+ zend_argument_value_error ( 2 , " length must be lower than %d" , MAX_NAME_LEN );
848
856
return false;
849
857
}
850
858
851
- if (timeout < -1 || timeout > LONG_MAX ) {
852
- zend_value_error ( "timeout must be between -1 and %ld" , LONG_MAX );
859
+ if (zend_str_has_nul_byte ( community ) ) {
860
+ zend_argument_value_error ( 3 , " must not contain any null bytes" );
853
861
return false;
854
862
}
855
863
856
- if (retries < -1 || retries > INT_MAX ) {
857
- zend_value_error ( "retries must be between -1 and %d" , INT_MAX );
864
+ if (ZSTR_LEN ( community ) == 0 ) {
865
+ zend_argument_value_error ( 3 , "cannot be empty" );
858
866
return false;
859
867
}
860
868
869
+ if (timeout_argument_offset != -1 ) {
870
+ if (timeout < -1 || timeout > LONG_MAX ) {
871
+ zend_argument_value_error (timeout_argument_offset , "must be between -1 and %ld" , LONG_MAX );
872
+ return false;
873
+ }
874
+
875
+ if (retries < -1 || retries > INT_MAX ) {
876
+ zend_argument_value_error (timeout_argument_offset , "must be between -1 and %d" , INT_MAX );
877
+ return false;
878
+ }
879
+ }
880
+
861
881
// TODO: Do not strip and re-add the port in peername?
862
882
unsigned short remote_port = SNMP_PORT ;
863
883
int tmp_port ;
@@ -1207,6 +1227,7 @@ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version)
1207
1227
struct objid_query objid_query ;
1208
1228
php_snmp_session * session ;
1209
1229
int session_less_mode = (getThis () == NULL );
1230
+ int timeout_argument_offset = -1 ;
1210
1231
php_snmp_object * snmp_object ;
1211
1232
php_snmp_object glob_snmp_object ;
1212
1233
@@ -1233,6 +1254,8 @@ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version)
1233
1254
Z_PARAM_LONG (timeout )
1234
1255
Z_PARAM_LONG (retries )
1235
1256
ZEND_PARSE_PARAMETERS_END ();
1257
+
1258
+ timeout_argument_offset = 10 ;
1236
1259
} else {
1237
1260
/* SNMP_CMD_GET
1238
1261
* SNMP_CMD_GETNEXT
@@ -1251,6 +1274,8 @@ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version)
1251
1274
Z_PARAM_LONG (timeout )
1252
1275
Z_PARAM_LONG (retries )
1253
1276
ZEND_PARSE_PARAMETERS_END ();
1277
+
1278
+ timeout_argument_offset = 9 ;
1254
1279
}
1255
1280
} else {
1256
1281
if (st & SNMP_CMD_SET ) {
@@ -1264,6 +1289,8 @@ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version)
1264
1289
Z_PARAM_LONG (timeout )
1265
1290
Z_PARAM_LONG (retries )
1266
1291
ZEND_PARSE_PARAMETERS_END ();
1292
+
1293
+ timeout_argument_offset = 6 ;
1267
1294
} else {
1268
1295
/* SNMP_CMD_GET
1269
1296
* SNMP_CMD_GETNEXT
@@ -1277,6 +1304,8 @@ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version)
1277
1304
Z_PARAM_LONG (timeout )
1278
1305
Z_PARAM_LONG (retries )
1279
1306
ZEND_PARSE_PARAMETERS_END ();
1307
+
1308
+ timeout_argument_offset = 4 ;
1280
1309
}
1281
1310
}
1282
1311
} else {
@@ -1320,7 +1349,7 @@ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version)
1320
1349
}
1321
1350
1322
1351
if (session_less_mode ) {
1323
- if (!netsnmp_session_init (& session , version , a1 , a2 , timeout , retries )) {
1352
+ if (!netsnmp_session_init (& session , version , a1 , a2 , timeout , retries , timeout_argument_offset )) {
1324
1353
php_free_objid_query (& objid_query , oid_ht , value_ht , st );
1325
1354
netsnmp_session_free (& session );
1326
1355
RETURN_FALSE ;
@@ -1624,7 +1653,7 @@ PHP_METHOD(SNMP, __construct)
1624
1653
netsnmp_session_free (& (snmp_object -> session ));
1625
1654
}
1626
1655
1627
- if (!netsnmp_session_init (& (snmp_object -> session ), version , a1 , a2 , timeout , retries )) {
1656
+ if (!netsnmp_session_init (& (snmp_object -> session ), version , a1 , a2 , timeout , retries , 4 )) {
1628
1657
return ;
1629
1658
}
1630
1659
snmp_object -> max_oids = 0 ;
0 commit comments