-
Notifications
You must be signed in to change notification settings - Fork 238
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
A number of fixes around strto*()
usage
#5827
Conversation
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.
There are few more places where strtouint*()
is called with 2nd parameter set to NULL:
src/sbus/sbus_errors.c
74: ret = strtouint32(error->message, NULL, 10);
src/responder/kcm/kcmsrv_ccache_secdb.c
846: uid = strtouint32(uid_list[i], NULL, 10);
src/tests/cwrap/test_server.c
79: tmp = strtouint32(buf, NULL, 10);
src/providers/ldap/ldap_id_services.c
266: port = strtouint16(state->name, NULL, 10);
src/providers/ldap/sdap_access.c
1859: duration = strtouint32(pwdAccountLockedDurationTime, NULL, 0);
If those are outside of the scope of this PR?
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 found call for strtoul()
in one more place:
src/providers/ldap/sdap_sudo_shared.c
194: strtoul(srv_opts->max_sudo_value, &timezone, 10);
204: usn_number = strtoul(usn, &timezone, 10);
I think in the 2nd case evaluation against > UINT32_MAX
is missing.
Generally LGTM, just two minor questions. |
I don't have very strong justification but will try my best to explain why I missed those.
This is a case
That's a test. It's not that I don't care at all, but it really can be not as strict.
Again, internal stuff. But ok, to be consistent I will add checks here...
This value is from LDAP - "pwdLockoutDuration" . I just wasn't sure what weird format it might have... |
Why? |
7e74aa7
to
074bd49
Compare
Done. |
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.
@alexey-tikhonov thank you for explanation, code vise LGTM, upstream CI is still spinning but if it will end up green ACK from me.
CI is green, ACK from me. |
Hi, it would be nice to have some description in the commit message that would make clear why the changes are required/correct without the need to peek into man page. |
To properly check for an error during string to number conversion one needs to: - check `errno` - check that something was really converted (i.e. start != end) - (if this is expected) check that entire string was consumed Some of those error conditions weren't checked in various locations over the code.
To properly check for an error during string to number conversion one needs to: - check `errno` - check that something was really converted (i.e. start != end) - (if this is expected) check that entire string was consumed Some of those error conditions weren't checked in various locations over the code.
Previously result of `AS_STR(OFFLINE_TIMEOUT)` was "OFFLINE_TIMEOUT" instead of expected integer value.
074bd49
to
b9757be
Compare
Done. |
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, just one small question.
@@ -571,9 +571,9 @@ static void enum_users_done(struct tevent_req *subreq) | |||
talloc_zfree(state->ctx->srv_opts->max_user_value); | |||
state->ctx->srv_opts->max_user_value = | |||
talloc_steal(state->ctx, usn_value); | |||
|
|||
errno = 0; |
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.
Small question: if in cases like this EOK
should not be used instead of 0
?
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 guess errno == 0
is so common that there is no point to use EOK
here explicit.
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.
tl,dr: no, it shouldn't. See man page: the calling program should set errno to 0 before the call
.
strto*()
set errno
in case specific errors happens, leave intact otherwise. Caller is required to reset errno
before the call. This means to set it to a value that doesn't indicate any error. 0
is typically used for this purpose. Using EOK
here is semantically wrong.
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.
Thank you for detailed explanation.
No description provided.