Skip to content
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

getaddrinfo bug fix #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

getaddrinfo bug fix #7

wants to merge 1 commit into from

Conversation

kyle-go
Copy link

@kyle-go kyle-go commented Aug 19, 2020

#3 bug fix.

@DragonQuestHero
Copy link

nice job

@XanYua98
Copy link

NTSTATUS
NTAPI
KspUtilAddrInfoExToAddrInfo(
In PADDRINFOEXW AddrInfoEx,
Out PADDRINFOA* AddrInfo
)
{
NTSTATUS Status;

//
// Convert NULL input into NULL output.
//

if (AddrInfoEx == NULL)
{
*AddrInfo = NULL;
return STATUS_SUCCESS;
}

//
// Allocate memory for the output structure.
//

PADDRINFOA Result = ExAllocatePoolWithTag(NonPagedPool, sizeof(ADDRINFOA) + sizeof(SOCKADDR), MEMORY_TAG);

if (Result == NULL)
{
Status = STATUS_INSUFFICIENT_RESOURCES;
goto Error1;
}

//
// Copy numeric values.
//

RtlZeroMemory(Result, sizeof(ADDRINFOA));
Result->ai_flags = AddrInfoEx->ai_flags;
Result->ai_family = AddrInfoEx->ai_family;
Result->ai_socktype = AddrInfoEx->ai_socktype;
Result->ai_protocol = AddrInfoEx->ai_protocol;
Result->ai_addrlen = AddrInfoEx->ai_addrlen;

//
// Copy canonical name.
//

UNICODE_STRING CanonicalNameUnicode = { 0 };
ANSI_STRING CanonicalNameAnsi = { 0 };

if (AddrInfoEx->ai_canonname)
{
RtlInitUnicodeString(&CanonicalNameUnicode, AddrInfoEx->ai_canonname);
Status = RtlUnicodeStringToAnsiString(&CanonicalNameAnsi, &CanonicalNameUnicode, TRUE);

if (!NT_SUCCESS(Status))
{
  goto Error2;
}

Result->ai_canonname = CanonicalNameAnsi.Buffer;

}

//
// Copy address.
//

PSOCKADDR ai_addr = (PSOCKADDR)((PUCHAR)Result + sizeof(ADDRINFOA));
memcpy(ai_addr, AddrInfoEx->ai_addr, sizeof(SOCKADDR));
Result->ai_addr = ai_addr;

//
// Copy the next structure (recursively).
//

PADDRINFOA NextAddrInfo;
Status = KspUtilAddrInfoExToAddrInfo(AddrInfoEx->ai_next, &NextAddrInfo);

if (!NT_SUCCESS(Status))
{
goto Error3;
}

Result->ai_next = NextAddrInfo;

//
// All done!
//

*AddrInfo = Result;

return Status;

Error3:
RtlFreeAnsiString(&CanonicalNameAnsi);

Error2:
ExFreePoolWithTag(Result, MEMORY_TAG);

Error1:
return Status;
}

//get ip fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants