Skip to content

Commit

Permalink
Fix error in hostname retrieval
Browse files Browse the repository at this point in the history
Fix off-by-one error in gethostname() param

Resolves:
https://pagure.io/SSSD/sssd/issue/3865

Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
  • Loading branch information
alexey-tikhonov authored and jhrozek committed Dec 13, 2018
1 parent 61e4ba5 commit 1706258
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/providers/ad/ad_common.c
Expand Up @@ -458,7 +458,7 @@ ad_get_common_options(TALLOC_CTX *mem_ctx,
*/
ad_hostname = dp_opt_get_string(opts->basic, AD_HOSTNAME);
if (ad_hostname == NULL) {
gret = gethostname(hostname, HOST_NAME_MAX);
gret = gethostname(hostname, sizeof(hostname));
if (gret != 0) {
ret = errno;
DEBUG(SSSDBG_FATAL_FAILURE,
Expand Down
2 changes: 1 addition & 1 deletion src/providers/data_provider_fo.c
Expand Up @@ -239,7 +239,7 @@ errno_t be_fo_set_dns_srv_lookup_plugin(struct be_ctx *be_ctx,
errno_t ret;

if (hostname == NULL) {
ret = gethostname(resolved_hostname, HOST_NAME_MAX);
ret = gethostname(resolved_hostname, sizeof(resolved_hostname));
if (ret != EOK) {
ret = errno;
DEBUG(SSSDBG_CRIT_FAILURE,
Expand Down
2 changes: 1 addition & 1 deletion src/providers/ipa/ipa_common.c
Expand Up @@ -79,7 +79,7 @@ int ipa_get_options(TALLOC_CTX *memctx,

ipa_hostname = dp_opt_get_string(opts->basic, IPA_HOSTNAME);
if (ipa_hostname == NULL) {
ret = gethostname(hostname, HOST_NAME_MAX);
ret = gethostname(hostname, sizeof(hostname));
if (ret != EOK) {
DEBUG(SSSDBG_CRIT_FAILURE, "gethostname failed [%d][%s].\n", errno,
strerror(errno));
Expand Down
2 changes: 1 addition & 1 deletion src/providers/ldap/ldap_child.c
Expand Up @@ -326,7 +326,7 @@ static krb5_error_code ldap_child_get_tgt_sync(TALLOC_CTX *memctx,
} else {
char hostname[HOST_NAME_MAX + 1];

ret = gethostname(hostname, HOST_NAME_MAX);
ret = gethostname(hostname, sizeof(hostname));
if (ret == -1) {
krberr = KRB5KRB_ERR_GENERIC;
goto done;
Expand Down
2 changes: 1 addition & 1 deletion src/providers/ldap/sdap_access.c
Expand Up @@ -1255,7 +1255,7 @@ static errno_t sdap_access_host(struct ldb_message *user_entry)
return ERR_ACCESS_DENIED;
}

if (gethostname(hostname, HOST_NAME_MAX) == -1) {
if (gethostname(hostname, sizeof(hostname)) == -1) {
DEBUG(SSSDBG_CRIT_FAILURE,
"Unable to get system hostname. Access denied\n");
return ERR_ACCESS_DENIED;
Expand Down
2 changes: 1 addition & 1 deletion src/providers/ldap/sdap_async_sudo_hostinfo.c
Expand Up @@ -380,7 +380,7 @@ static struct tevent_req *sdap_sudo_get_hostnames_send(TALLOC_CTX *mem_ctx,
/* get hostname */

errno = 0;
ret = gethostname(hostname, HOST_NAME_MAX);
ret = gethostname(hostname, sizeof(hostname));
if (ret != EOK) {
ret = errno;
DEBUG(SSSDBG_CRIT_FAILURE, "Unable to retrieve machine hostname "
Expand Down
2 changes: 1 addition & 1 deletion src/resolv/async_resolv_utils.c
Expand Up @@ -57,7 +57,7 @@ resolv_get_domain_send(TALLOC_CTX *mem_ctx,

if (hostname == NULL) {
/* use system hostname */
ret = gethostname(system_hostname, HOST_NAME_MAX);
ret = gethostname(system_hostname, sizeof(system_hostname));
if (ret) {
ret = errno;
DEBUG(SSSDBG_CRIT_FAILURE, "gethostname() failed: [%d]: %s\n",
Expand Down

0 comments on commit 1706258

Please sign in to comment.