@@ -655,7 +655,8 @@ static void php_free_objid_query(struct objid_query *objid_query, HashTable* oid
655655*/
656656static bool php_snmp_parse_oid (
657657 zval * object , int st , struct objid_query * objid_query , zend_string * oid_str , HashTable * oid_ht ,
658- zend_string * type_str , HashTable * type_ht , zend_string * value_str , HashTable * value_ht
658+ zend_string * type_str , HashTable * type_ht , zend_string * value_str , HashTable * value_ht ,
659+ uint32_t oid_argument_offset , uint32_t type_argument_offset , uint32_t value_argument_offset
659660) {
660661 char * pptr ;
661662 uint32_t idx_type = 0 , idx_value = 0 ;
@@ -682,7 +683,7 @@ static bool php_snmp_parse_oid(
682683 ZEND_ASSERT (type_str && value_str );
683684
684685 if (ZSTR_LEN (type_str ) != 1 ) {
685- zend_value_error ( "Type must be a single character" );
686+ zend_argument_value_error ( type_argument_offset , " must be a single character" );
686687 efree (objid_query -> vars );
687688 return false;
688689 }
@@ -693,7 +694,7 @@ static bool php_snmp_parse_oid(
693694 objid_query -> count ++ ;
694695 } else if (oid_ht ) { /* we got objid array */
695696 if (zend_hash_num_elements (oid_ht ) == 0 ) {
696- zend_value_error ( "Array of object IDs must not be empty" );
697+ zend_argument_value_error ( oid_argument_offset , " must not be empty when passed as an array " );
697698 return false;
698699 }
699700 objid_query -> vars = (snmpobjarg * )safe_emalloc (sizeof (snmpobjarg ), zend_hash_num_elements (oid_ht ), 0 );
@@ -738,14 +739,14 @@ static bool php_snmp_parse_oid(
738739 char ptype = * ZSTR_VAL (type );
739740 zend_string_release (type );
740741 if (len != 1 ) {
741- zend_value_error ( "Type must be a single character" );
742+ zend_argument_value_error ( type_argument_offset , " must be a single character" );
742743 php_free_objid_query (objid_query , oid_ht , value_ht , st );
743744 return false;
744745 }
745746 objid_query -> vars [objid_query -> count ].type = ptype ;
746747 idx_type ++ ;
747748 } else {
748- zend_value_error ( "'%s': no type set " , ZSTR_VAL (tmp ));
749+ zend_argument_value_error ( type_argument_offset , "must contain a type for object ID '%s' " , ZSTR_VAL (tmp ));
749750 php_free_objid_query (objid_query , oid_ht , value_ht , st );
750751 return false;
751752 }
@@ -780,7 +781,7 @@ static bool php_snmp_parse_oid(
780781 objid_query -> vars [objid_query -> count ].value = ZSTR_VAL (tmp );
781782 idx_value ++ ;
782783 } else {
783- zend_value_error ( "'%s': no value set " , ZSTR_VAL (tmp ));
784+ zend_argument_value_error ( value_argument_offset , "must contain a value for object ID '%s' " , ZSTR_VAL (tmp ));
784785 php_free_objid_query (objid_query , oid_ht , value_ht , st );
785786 return false;
786787 }
@@ -827,7 +828,7 @@ static bool php_snmp_parse_oid(
827828/* {{{ snmp_session_init
828829 allocates memory for session and session->peername, caller should free it manually using snmp_session_free() and efree()
829830*/
830- static bool snmp_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 )
831+ static bool snmp_session_init (php_snmp_session * * session_p , int version , zend_string * hostname , zend_string * community , zend_long timeout , zend_long retries , int hostname_argument_offset , int timeout_argument_offset )
831832{
832833 php_snmp_session * session ;
833834 char * pptr , * host_ptr ;
@@ -842,22 +843,22 @@ static bool snmp_session_init(php_snmp_session **session_p, int version, zend_st
842843 ZEND_ASSERT (community != NULL );
843844
844845 if (zend_str_has_nul_byte (hostname )) {
845- zend_argument_value_error (2 , "must not contain any null bytes" );
846+ zend_argument_value_error (hostname_argument_offset , "must not contain any null bytes" );
846847 return false;
847848 }
848849
849850 if (ZSTR_LEN (hostname ) >= MAX_NAME_LEN ) {
850- zend_argument_value_error (2 , "length must be lower than %d" , MAX_NAME_LEN );
851+ zend_argument_value_error (hostname_argument_offset , "length must be lower than %d" , MAX_NAME_LEN );
851852 return false;
852853 }
853854
854855 if (zend_str_has_nul_byte (community )) {
855- zend_argument_value_error (3 , "must not contain any null bytes" );
856+ zend_argument_value_error (hostname_argument_offset + 1 , "must not contain any null bytes" );
856857 return false;
857858 }
858859
859860 if (ZSTR_LEN (community ) == 0 ) {
860- zend_argument_must_not_be_empty_error (3 );
861+ zend_argument_must_not_be_empty_error (hostname_argument_offset + 1 );
861862 return false;
862863 }
863864
@@ -899,22 +900,22 @@ static bool snmp_session_init(php_snmp_session **session_p, int version, zend_st
899900 char * pport = pptr + 2 ;
900901 tmp_port = atoi (pport );
901902 if (tmp_port < 0 || tmp_port > USHRT_MAX ) {
902- zend_argument_value_error (2 , "remote port must be between 0 and %u" , USHRT_MAX );
903+ zend_argument_value_error (hostname_argument_offset , "remote port must be between 0 and %u" , USHRT_MAX );
903904 return false;
904905 }
905906 remote_port = (unsigned short )tmp_port ;
906907 }
907908 * pptr = '\0' ;
908909 } else {
909- zend_value_error ( "Malformed IPv6 address, closing square bracket missing" );
910+ zend_argument_value_error ( hostname_argument_offset , "has a malformed IPv6 address, closing square bracket missing" );
910911 return false;
911912 }
912913 } else { /* IPv4 address */
913914 if ((pptr = strchr (host_ptr , ':' ))) {
914915 char * pport = pptr + 1 ;
915916 tmp_port = atoi (pport );
916917 if (tmp_port < 0 || tmp_port > USHRT_MAX ) {
917- zend_argument_value_error (2 , "remote port must be between 0 and %u" , USHRT_MAX );
918+ zend_argument_value_error (hostname_argument_offset , "remote port must be between 0 and %u" , USHRT_MAX );
918919 return false;
919920 }
920921 remote_port = (unsigned short )tmp_port ;
@@ -1122,13 +1123,13 @@ static bool snmp_session_gen_sec_key(struct snmp_session *s, zend_string *pass)
11221123/* }}} */
11231124
11241125/* {{{ Set context Engine Id in the snmpv3 session */
1125- static bool snmp_session_set_contextEngineID (struct snmp_session * s , zend_string * contextEngineID )
1126+ static bool snmp_session_set_contextEngineID (struct snmp_session * s , zend_string * contextEngineID , uint32_t contextEngineID_argument_offset )
11261127{
11271128 size_t ebuf_len = 32 , eout_len = 0 ;
11281129 uint8_t * ebuf = (uint8_t * ) emalloc (ebuf_len );
11291130
11301131 if (!snmp_hex_to_binary (& ebuf , & ebuf_len , & eout_len , 1 , ZSTR_VAL (contextEngineID ))) {
1131- zend_value_error ( "Bad engine ID value '%s'" , ZSTR_VAL ( contextEngineID ) );
1132+ zend_argument_value_error ( contextEngineID_argument_offset , "must be a valid context engine ID" );
11321133 efree (ebuf );
11331134 return false;
11341135 }
@@ -1146,7 +1147,8 @@ static bool snmp_session_set_contextEngineID(struct snmp_session *s, zend_string
11461147/* {{{ Set all snmpv3-related security options */
11471148static bool snmp_session_set_security (struct snmp_session * session , zend_string * sec_level ,
11481149 zend_string * auth_protocol , zend_string * auth_passphrase , zend_string * priv_protocol ,
1149- zend_string * priv_passphrase , zend_string * contextName , zend_string * contextEngineID )
1150+ zend_string * priv_passphrase , zend_string * contextName , zend_string * contextEngineID ,
1151+ uint32_t contextEngineID_argument_offset )
11501152{
11511153
11521154 /* Setting the security level. */
@@ -1191,7 +1193,7 @@ static bool snmp_session_set_security(struct snmp_session *session, zend_string
11911193 }
11921194
11931195 /* Setting contextEngineIS if specified */
1194- if (contextEngineID && ZSTR_LEN (contextEngineID ) && !snmp_session_set_contextEngineID (session , contextEngineID )) {
1196+ if (contextEngineID && ZSTR_LEN (contextEngineID ) && !snmp_session_set_contextEngineID (session , contextEngineID , contextEngineID_argument_offset )) {
11951197 /* Warning message sent already, just bail out */
11961198 return false;
11971199 }
@@ -1219,6 +1221,7 @@ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version)
12191221 php_snmp_session * session ;
12201222 int session_less_mode = (getThis () == NULL );
12211223 int timeout_argument_offset = -1 ;
1224+ uint32_t oid_argument_offset = 1 , type_argument_offset = 0 , value_argument_offset = 0 ;
12221225 php_snmp_object * snmp_object ;
12231226 php_snmp_object glob_snmp_object ;
12241227
@@ -1247,6 +1250,9 @@ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version)
12471250 ZEND_PARSE_PARAMETERS_END ();
12481251
12491252 timeout_argument_offset = 10 ;
1253+ oid_argument_offset = 8 ;
1254+ type_argument_offset = 9 ;
1255+ value_argument_offset = 10 ;
12501256 } else {
12511257 /* SNMP_CMD_GET
12521258 * SNMP_CMD_GETNEXT
@@ -1267,6 +1273,7 @@ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version)
12671273 ZEND_PARSE_PARAMETERS_END ();
12681274
12691275 timeout_argument_offset = 9 ;
1276+ oid_argument_offset = 8 ;
12701277 }
12711278 } else {
12721279 if (st & SNMP_CMD_SET ) {
@@ -1282,6 +1289,9 @@ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version)
12821289 ZEND_PARSE_PARAMETERS_END ();
12831290
12841291 timeout_argument_offset = 6 ;
1292+ oid_argument_offset = 3 ;
1293+ type_argument_offset = 4 ;
1294+ value_argument_offset = 5 ;
12851295 } else {
12861296 /* SNMP_CMD_GET
12871297 * SNMP_CMD_GETNEXT
@@ -1297,6 +1307,7 @@ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version)
12971307 ZEND_PARSE_PARAMETERS_END ();
12981308
12991309 timeout_argument_offset = 4 ;
1310+ oid_argument_offset = 3 ;
13001311 }
13011312 }
13021313 } else {
@@ -1306,6 +1317,8 @@ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version)
13061317 Z_PARAM_ARRAY_HT_OR_STR (type_ht , type_str )
13071318 Z_PARAM_ARRAY_HT_OR_STR (value_ht , value_str )
13081319 ZEND_PARSE_PARAMETERS_END ();
1320+ type_argument_offset = 2 ;
1321+ value_argument_offset = 3 ;
13091322 } else if (st & SNMP_CMD_WALK ) {
13101323 ZEND_PARSE_PARAMETERS_START (1 , 4 )
13111324 Z_PARAM_ARRAY_HT_OR_STR (oid_ht , oid_str )
@@ -1335,17 +1348,18 @@ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version)
13351348 }
13361349 }
13371350
1338- if (!php_snmp_parse_oid (getThis (), st , & objid_query , oid_str , oid_ht , type_str , type_ht , value_str , value_ht )) {
1351+ if (!php_snmp_parse_oid (getThis (), st , & objid_query , oid_str , oid_ht , type_str , type_ht , value_str , value_ht ,
1352+ oid_argument_offset , type_argument_offset , value_argument_offset )) {
13391353 RETURN_FALSE ;
13401354 }
13411355
13421356 if (session_less_mode ) {
1343- if (!snmp_session_init (& session , version , a1 , a2 , timeout , retries , timeout_argument_offset )) {
1357+ if (!snmp_session_init (& session , version , a1 , a2 , timeout , retries , 1 , timeout_argument_offset )) {
13441358 php_free_objid_query (& objid_query , oid_ht , value_ht , st );
13451359 snmp_session_free (& session );
13461360 RETURN_FALSE ;
13471361 }
1348- if (version == SNMP_VERSION_3 && !snmp_session_set_security (session , a3 , a4 , a5 , a6 , a7 , NULL , NULL )) {
1362+ if (version == SNMP_VERSION_3 && !snmp_session_set_security (session , a3 , a4 , a5 , a6 , a7 , NULL , NULL , 0 )) {
13491363 php_free_objid_query (& objid_query , oid_ht , value_ht , st );
13501364 snmp_session_free (& session );
13511365 /* Warning message sent already, just bail out */
@@ -1644,7 +1658,7 @@ PHP_METHOD(SNMP, __construct)
16441658 snmp_session_free (& (snmp_object -> session ));
16451659 }
16461660
1647- if (!snmp_session_init (& (snmp_object -> session ), version , a1 , a2 , timeout , retries , 4 )) {
1661+ if (!snmp_session_init (& (snmp_object -> session ), version , a1 , a2 , timeout , retries , 2 , 4 )) {
16481662 return ;
16491663 }
16501664 snmp_object -> max_oids = 0 ;
@@ -1720,7 +1734,7 @@ PHP_METHOD(SNMP, setSecurity)
17201734 RETURN_THROWS ();
17211735 }
17221736
1723- if (!snmp_session_set_security (snmp_object -> session , a1 , a2 , a3 , a4 , a5 , a6 , a7 )) {
1737+ if (!snmp_session_set_security (snmp_object -> session , a1 , a2 , a3 , a4 , a5 , a6 , a7 , 7 )) {
17241738 /* Warning message sent already, just bail out */
17251739 RETURN_FALSE ;
17261740 }
0 commit comments