From 58b335985e75672e4de699351ab1182cbd7aa990 Mon Sep 17 00:00:00 2001 From: Pavel Březina Date: Mon, 16 Jul 2012 15:30:38 +0200 Subject: 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. --- src/resolv/async_resolv.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'src/resolv/async_resolv.c') diff --git a/src/resolv/async_resolv.c b/src/resolv/async_resolv.c index ff19050b0..81adf098a 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 -- cgit