diff options
author | Pavel Březina <pbrezina@redhat.com> | 2012-07-16 15:30:38 +0200 |
---|---|---|
committer | Stephen Gallagher <sgallagh@redhat.com> | 2012-07-16 10:25:26 -0400 |
commit | 58b335985e75672e4de699351ab1182cbd7aa990 (patch) | |
tree | 1f4a27f8d419ced702a82f8915f9850e825092ce /src/resolv | |
parent | b996569ec09cf7eaffc4d38306db6d9069fa954f (diff) | |
download | sssd-58b335985e75672e4de699351ab1182cbd7aa990.tar.gz sssd-58b335985e75672e4de699351ab1182cbd7aa990.tar.bz2 sssd-58b335985e75672e4de699351ab1182cbd7aa990.zip |
resolv_gethostbyname_send: strdup hostname to work properly when hostname is allocated on stack
If we provide a hostname that was allocated on stack, it may contain
invalid data in the time when it is actually resolved.
This patch fixes it.
Diffstat (limited to 'src/resolv')
-rw-r--r-- | src/resolv/async_resolv.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/resolv/async_resolv.c b/src/resolv/async_resolv.c index ff19050b..81adf098 100644 --- a/src/resolv/async_resolv.c +++ b/src/resolv/async_resolv.c @@ -1140,7 +1140,12 @@ resolv_gethostbyname_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, state->resolv_ctx = ctx; state->ev = ev; - state->name = name; + state->name = talloc_strdup(state, name); + if (state->name == NULL) { + DEBUG(SSSDBG_CRIT_FAILURE, ("talloc_strdup() failed\n")); + goto fail; + } + state->rhostent = NULL; state->status = 0; state->timeouts = 0; @@ -1156,8 +1161,7 @@ resolv_gethostbyname_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, &state->rhostent); if (ret != EOK) { DEBUG(1, ("Canot create a fake hostent structure\n")); - talloc_zfree(req); - return NULL; + goto fail; } tevent_req_done(req); @@ -1168,11 +1172,14 @@ resolv_gethostbyname_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, ret = resolv_gethostbyname_step(req); if (ret != EOK) { DEBUG(1, ("Cannot start the resolving\n")); - talloc_zfree(req); - return NULL; + goto fail; } return req; + +fail: + talloc_zfree(req); + return NULL; } static bool |