From e034072c96962754a222b5d4d436db4c4256a7f3 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 8 Sep 2020 13:58:49 -0700 Subject: [PATCH] libcli: nbt: Fix resolve_lmhosts_file_as_sockaddr() to return size_t * count of addresses. Signed-off-by: Jeremy Allison Reviewed-by: Noel Power --- libcli/nbt/libnbt.h | 2 +- libcli/nbt/lmhosts.c | 7 +------ source3/libsmb/namequery.c | 9 ++++++++- source4/libcli/resolve/lmhosts.c | 2 +- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/libcli/nbt/libnbt.h b/libcli/nbt/libnbt.h index 496b2b91783..204484be73f 100644 --- a/libcli/nbt/libnbt.h +++ b/libcli/nbt/libnbt.h @@ -372,6 +372,6 @@ NTSTATUS resolve_lmhosts_file_as_sockaddr(TALLOC_CTX *mem_ctx, const char *name, int name_type, struct sockaddr_storage **return_iplist, - int *return_count); + size_t *return_count); #endif /* __LIBNBT_H__ */ diff --git a/libcli/nbt/lmhosts.c b/libcli/nbt/lmhosts.c index 7c00567fdba..dd06e70c071 100644 --- a/libcli/nbt/lmhosts.c +++ b/libcli/nbt/lmhosts.c @@ -164,7 +164,7 @@ NTSTATUS resolve_lmhosts_file_as_sockaddr(TALLOC_CTX *mem_ctx, const char *name, int name_type, struct sockaddr_storage **return_iplist, - int *return_count) + size_t *return_count) { /* * "lmhosts" means parse the local lmhosts file. @@ -234,11 +234,6 @@ NTSTATUS resolve_lmhosts_file_as_sockaddr(TALLOC_CTX *mem_ctx, break; } - if ((int)ret_count < 0) { - TALLOC_FREE(ctx); - endlmhosts(fp); - return NT_STATUS_INVALID_PARAMETER; - } *return_count = ret_count; *return_iplist = talloc_move(mem_ctx, &iplist); TALLOC_FREE(ctx); diff --git a/source3/libsmb/namequery.c b/source3/libsmb/namequery.c index 324f391cc4d..67f3f29c7cb 100644 --- a/source3/libsmb/namequery.c +++ b/source3/libsmb/namequery.c @@ -3406,16 +3406,23 @@ NTSTATUS internal_resolve_name(TALLOC_CTX *ctx, } goto done; } else if (strequal(tok, "lmhosts")) { + size_t lmcount = 0; status = resolve_lmhosts_file_as_sockaddr( talloc_tos(), get_dyn_LMHOSTSFILE(), name, name_type, &ss_list, - &icount); + &lmcount); if (!NT_STATUS_IS_OK(status)) { continue; } + /* + * This uglyness will go away once + * all resolve_XXX() return size_t * + * number of addresses. + */ + icount = (int)lmcount; goto done; } else if (strequal(tok, "wins")) { size_t wcount = 0; diff --git a/source4/libcli/resolve/lmhosts.c b/source4/libcli/resolve/lmhosts.c index 0f2cf99b459..244a9a3ceaf 100644 --- a/source4/libcli/resolve/lmhosts.c +++ b/source4/libcli/resolve/lmhosts.c @@ -53,7 +53,7 @@ static struct composite_context *resolve_name_lmhosts_send( struct composite_context *c; struct resolve_lmhosts_state *state; struct sockaddr_storage *resolved_iplist; - int resolved_count, i; + size_t resolved_count = 0, i; if (event_ctx == NULL) { return NULL;