Skip to content

Commit 293b85e

Browse files
committed
Fix GH-21336: use zend_argument_value_error in snmp setSecurity.
1 parent 097bccf commit 293b85e

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

ext/snmp/snmp.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,7 +1105,8 @@ static bool netsnmp_session_set_contextEngineID(struct snmp_session *s, zend_str
11051105
/* {{{ Set all snmpv3-related security options */
11061106
static ZEND_ATTRIBUTE_NONNULL_ARGS(2) bool netsnmp_session_set_security(struct snmp_session *session, zend_string *sec_level,
11071107
zend_string *auth_protocol, zend_string *auth_passphrase, zend_string *priv_protocol,
1108-
zend_string *priv_passphrase, zend_string *contextName, zend_string *contextEngineID)
1108+
zend_string *priv_passphrase, zend_string *contextName, zend_string *contextEngineID,
1109+
uint32_t auth_protocol_argnum)
11091110
{
11101111

11111112
/* Setting the security level. */
@@ -1117,7 +1118,7 @@ static ZEND_ATTRIBUTE_NONNULL_ARGS(2) bool netsnmp_session_set_security(struct s
11171118
if (session->securityLevel == SNMP_SEC_LEVEL_AUTHNOPRIV || session->securityLevel == SNMP_SEC_LEVEL_AUTHPRIV) {
11181119

11191120
if (!auth_protocol) {
1120-
zend_value_error("Authentication protocol is required for security level \"authNoPriv\" or \"authPriv\"");
1121+
zend_argument_value_error(auth_protocol_argnum, "cannot be null when security level is \"authNoPriv\" or \"authPriv\"");
11211122
return false;
11221123
}
11231124

@@ -1128,7 +1129,7 @@ static ZEND_ATTRIBUTE_NONNULL_ARGS(2) bool netsnmp_session_set_security(struct s
11281129
}
11291130

11301131
if (!auth_passphrase) {
1131-
zend_value_error("Authentication passphrase is required for security level \"authNoPriv\" or \"authPriv\"");
1132+
zend_argument_value_error(auth_protocol_argnum + 1, "cannot be null when security level is \"authNoPriv\" or \"authPriv\"");
11321133
return false;
11331134
}
11341135

@@ -1141,7 +1142,7 @@ static ZEND_ATTRIBUTE_NONNULL_ARGS(2) bool netsnmp_session_set_security(struct s
11411142
if (session->securityLevel == SNMP_SEC_LEVEL_AUTHPRIV) {
11421143

11431144
if (!priv_protocol) {
1144-
zend_value_error("Privacy protocol is required for security level \"authPriv\"");
1145+
zend_argument_value_error(auth_protocol_argnum + 2, "cannot be null when security level is \"authPriv\"");
11451146
return false;
11461147
}
11471148

@@ -1152,7 +1153,7 @@ static ZEND_ATTRIBUTE_NONNULL_ARGS(2) bool netsnmp_session_set_security(struct s
11521153
}
11531154

11541155
if (!priv_passphrase) {
1155-
zend_value_error("Privacy passphrase is required for security level \"authPriv\"");
1156+
zend_argument_value_error(auth_protocol_argnum + 3, "cannot be null when security level is \"authPriv\"");
11561157
return false;
11571158
}
11581159

@@ -1316,7 +1317,7 @@ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version)
13161317
netsnmp_session_free(&session);
13171318
RETURN_FALSE;
13181319
}
1319-
if (version == SNMP_VERSION_3 && !netsnmp_session_set_security(session, a3, a4, a5, a6, a7, NULL, NULL)) {
1320+
if (version == SNMP_VERSION_3 && !netsnmp_session_set_security(session, a3, a4, a5, a6, a7, NULL, NULL, 4)) {
13201321
php_free_objid_query(&objid_query, oid_ht, value_ht, st);
13211322
netsnmp_session_free(&session);
13221323
/* Warning message sent already, just bail out */
@@ -1691,7 +1692,7 @@ PHP_METHOD(SNMP, setSecurity)
16911692
RETURN_THROWS();
16921693
}
16931694

1694-
if (!netsnmp_session_set_security(snmp_object->session, a1, a2, a3, a4, a5, a6, a7)) {
1695+
if (!netsnmp_session_set_security(snmp_object->session, a1, a2, a3, a4, a5, a6, a7, 2)) {
16951696
/* Warning message sent already, just bail out */
16961697
RETURN_FALSE;
16971698
}

ext/snmp/tests/gh21336.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ try {
3535
}
3636
?>
3737
--EXPECT--
38-
Authentication protocol is required for security level "authNoPriv" or "authPriv"
39-
Authentication passphrase is required for security level "authNoPriv" or "authPriv"
40-
Privacy protocol is required for security level "authPriv"
41-
Privacy passphrase is required for security level "authPriv"
38+
SNMP::setSecurity(): Argument #2 ($authProtocol) cannot be null when security level is "authNoPriv" or "authPriv"
39+
SNMP::setSecurity(): Argument #3 ($authPassphrase) cannot be null when security level is "authNoPriv" or "authPriv"
40+
SNMP::setSecurity(): Argument #4 ($privacyProtocol) cannot be null when security level is "authPriv"
41+
SNMP::setSecurity(): Argument #5 ($privacyPassphrase) cannot be null when security level is "authPriv"

0 commit comments

Comments
 (0)