-
Notifications
You must be signed in to change notification settings - Fork 7.8k
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
Conversation
42a05c7
to
460a2a4
Compare
51ff1fb
to
212fa80
Compare
212fa80
to
8dfc82d
Compare
There was a problem hiding this 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() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
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; | ||
} |
There was a problem hiding this comment.
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.
1c8662d
to
051a82a
Compare
ext/snmp/snmp.c
Outdated
} | ||
|
||
if (ZSTR_LEN(community) == 0) { | ||
zend_argument_value_error(3, "cannot be empty"); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true true..
There was a problem hiding this 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.
No description provided.