Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ext/snmp: various internals rewrite. #17368

Closed
wants to merge 10 commits into from

Conversation

devnexen
Copy link
Member

@devnexen devnexen commented Jan 5, 2025

No description provided.

@devnexen devnexen marked this pull request as ready for review January 6, 2025 07:57
@devnexen devnexen force-pushed the snmp_upd_master branch 2 times, most recently from 51ff1fb to 212fa80 Compare January 25, 2025 21:48
@devnexen devnexen requested a review from Girgias January 25, 2025 21:49
Copy link
Member

@Girgias Girgias left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel the function renaming should be done in a separate commit, as I was expecting the review to be touching a bunch of stuff, and it convolutes the commit/PR somewhat.

ext/snmp/snmp.c Outdated
/* {{{ netsnmp_session_init
allocates memory for session and session->peername, caller should free it manually using netsnmp_session_free() and efree()
/* {{{ snmp_session_init
allocates memory for session and session->peername, caller should free it manually using session_free() and efree()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
allocates memory for session and session->peername, caller should free it manually using session_free() and efree()
allocates memory for session and session->peername, caller should free it manually using snmp_session_free() and efree()

ext/snmp/snmp.c Outdated
Comment on lines 846 to 859
if (ZSTR_LEN(hostname) >= MAX_NAME_LEN) {
zend_value_error("hostname length must be lower than %d", MAX_NAME_LEN);
return false;
}

if (timeout < -1 || timeout > LONG_MAX) {
zend_value_error("timeout must be between -1 and %ld", LONG_MAX);
return false;
}

if (retries < -1 || retries > INT_MAX) {
zend_value_error("retries must be between -1 and %d", INT_MAX);
return false;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we pass the arg_nums to these parameters? Does the community zend_string need to be checked too? Is Hostname checked to not contain null bytes prior to calling this function? If yes please add an assertion.

ext/snmp/snmp.c Outdated
}

if (ZSTR_LEN(community) == 0) {
zend_argument_value_error(3, "cannot be empty");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the helper function for this to have a consistant error message.

ext/snmp/snmp.c Outdated
char *pport = pptr + 2;
tmp_port = atoi(pport);
if (tmp_port < 0 || tmp_port > USHRT_MAX) {
zend_value_error("remote port must be between 0 and %u", USHRT_MAX);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the argument version for it and use the host arg number, as the error message does not point where the error is.

ext/snmp/snmp.c Outdated
char *pport = pptr + 1;
tmp_port = atoi(pport);
if (tmp_port < 0 || tmp_port > USHRT_MAX) {
zend_value_error("remote port must be between 0 and %u", USHRT_MAX);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

SNMP::__construct(): Argument #4 ($timeout) must be between -1 and %d
SNMP::__construct(): Argument #5 ($retries) must be between -1 and %d
SNMP::__construct(): Argument #2 ($hostname) must not contain any null bytes
SNMP::__construct(): Argument #3 ($community) cannot be empty
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the wrong test expectation

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true true..

Copy link
Member

@Girgias Girgias left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM if CI is green, please don't forget to split the function renaming from the argument validation when merging.

@devnexen devnexen closed this in 81458f5 Jan 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants