Fixup hosts cache thanks to patch from @danielk43

Closes https://github.com/Divested-Mobile/DivestOS-Build/issues/198

Signed-off-by: Tad <tad@spotco.us>
This commit is contained in:
Tad 2023-08-18 11:17:13 -04:00
parent 1485be072d
commit ceec1584a9
No known key found for this signature in database
GPG Key ID: B286E9F57A07424B
6 changed files with 105 additions and 0 deletions

View File

@ -0,0 +1,34 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: danielk43 <11856117+danielk43@users.noreply.github.com>
Date: Sun, 26 Mar 2023 11:37:26 -0400
Subject: [PATCH] Reuse align_ptr in hosts_cache
Change-Id: I461718c38ca3c0e372e1cc0e0f0deb74ae5c68bb
---
hosts_cache.cpp | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/hosts_cache.cpp b/hosts_cache.cpp
index 258eac1b..be8a0ff4 100644
--- a/hosts_cache.cpp
+++ b/hosts_cache.cpp
@@ -47,10 +47,6 @@ constexpr int MAXADDRS = 35;
#define ESTIMATED_LINELEN 32
#define HCFILE_ALLOC_SIZE 256
-/* From sethostent.c */
-#define ALIGNBYTES (sizeof(uintptr_t) - 1)
-#define ALIGN(p) (((uintptr_t)(p) + ALIGNBYTES) &~ ALIGNBYTES)
-
/*
* Host cache entry for hcfile.c_data.
* Offsets are into hcfile.h_data.
@@ -500,7 +496,7 @@ int hc_gethtbyname(const char *host, int af, struct getnamaddr *info)
if (naliases >= MAXALIASES)
goto nospc;
}
- aligned = (char *)ALIGN(info->buf);
+ aligned = align_ptr(info->buf);
if (info->buf != aligned) {
if ((ptrdiff_t)info->buflen < (aligned - info->buf))
goto nospc;

View File

@ -0,0 +1,34 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: danielk43 <11856117+danielk43@users.noreply.github.com>
Date: Sun, 26 Mar 2023 11:37:26 -0400
Subject: [PATCH] Reuse align_ptr in hosts_cache
Change-Id: I461718c38ca3c0e372e1cc0e0f0deb74ae5c68bb
---
hosts_cache.cpp | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/hosts_cache.cpp b/hosts_cache.cpp
index 258eac1b..be8a0ff4 100644
--- a/hosts_cache.cpp
+++ b/hosts_cache.cpp
@@ -47,10 +47,6 @@ constexpr int MAXADDRS = 35;
#define ESTIMATED_LINELEN 32
#define HCFILE_ALLOC_SIZE 256
-/* From sethostent.c */
-#define ALIGNBYTES (sizeof(uintptr_t) - 1)
-#define ALIGN(p) (((uintptr_t)(p) + ALIGNBYTES) &~ ALIGNBYTES)
-
/*
* Host cache entry for hcfile.c_data.
* Offsets are into hcfile.h_data.
@@ -500,7 +496,7 @@ int hc_gethtbyname(const char *host, int af, struct getnamaddr *info)
if (naliases >= MAXALIASES)
goto nospc;
}
- aligned = (char *)ALIGN(info->buf);
+ aligned = align_ptr(info->buf);
if (info->buf != aligned) {
if ((ptrdiff_t)info->buflen < (aligned - info->buf))
goto nospc;

View File

@ -0,0 +1,34 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: danielk43 <11856117+danielk43@users.noreply.github.com>
Date: Sun, 26 Mar 2023 11:37:26 -0400
Subject: [PATCH] Reuse align_ptr in hosts_cache
Change-Id: I461718c38ca3c0e372e1cc0e0f0deb74ae5c68bb
---
hosts_cache.cpp | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/hosts_cache.cpp b/hosts_cache.cpp
index 258eac1b..be8a0ff4 100644
--- a/hosts_cache.cpp
+++ b/hosts_cache.cpp
@@ -47,10 +47,6 @@ constexpr int MAXADDRS = 35;
#define ESTIMATED_LINELEN 32
#define HCFILE_ALLOC_SIZE 256
-/* From sethostent.c */
-#define ALIGNBYTES (sizeof(uintptr_t) - 1)
-#define ALIGN(p) (((uintptr_t)(p) + ALIGNBYTES) &~ ALIGNBYTES)
-
/*
* Host cache entry for hcfile.c_data.
* Offsets are into hcfile.h_data.
@@ -500,7 +496,7 @@ int hc_gethtbyname(const char *host, int af, struct getnamaddr *info)
if (naliases >= MAXALIASES)
goto nospc;
}
- aligned = (char *)ALIGN(info->buf);
+ aligned = align_ptr(info->buf);
if (info->buf != aligned) {
if ((ptrdiff_t)info->buflen < (aligned - info->buf))
goto nospc;

View File

@ -356,6 +356,7 @@ applyPatch "$DOS_PATCHES_COMMON/android_packages_inputmethods_LatinIME/0002-Disa
fi;
if enterAndClear "packages/modules/DnsResolver"; then
applyPatch "$DOS_PATCHES/android_packages_modules_DnsResolver/0003-Reuse-align_ptr-in-hosts_cache.patch"; #Reuse align_ptr in hosts_cache (danielk43)
applyPatch "$DOS_PATCHES/android_packages_modules_DnsResolver/0001-hosts_toggle.patch"; #Add a toggle to disable /etc/hosts lookup (DivestOS)
fi;

View File

@ -345,6 +345,7 @@ if enterAndClear "packages/modules/DnsResolver"; then
applyPatch "$DOS_PATCHES/android_packages_modules_DnsResolver/0001-Hosts_Cache.patch"; #DnsResolver: Sort and cache hosts file data for fast lookup (tdm)
applyPatch "$DOS_PATCHES/android_packages_modules_DnsResolver/0001-Hosts_Wildcards.patch"; #DnsResolver: Support wildcards in cached hosts file (tdm)
applyPatch "$DOS_PATCHES/android_packages_modules_DnsResolver/0002-hosts_toggle.patch"; #Add a toggle to disable /etc/hosts lookup (DivestOS)
applyPatch "$DOS_PATCHES/android_packages_modules_DnsResolver/0003-Reuse-align_ptr-in-hosts_cache.patch"; #Reuse align_ptr in hosts_cache (danielk43)
fi;
if enterAndClear "packages/modules/NetworkStack"; then

View File

@ -346,6 +346,7 @@ if enterAndClear "packages/modules/DnsResolver"; then
applyPatch "$DOS_PATCHES/android_packages_modules_DnsResolver/0001-Hosts_Cache.patch"; #DnsResolver: Sort and cache hosts file data for fast lookup (tdm)
applyPatch "$DOS_PATCHES/android_packages_modules_DnsResolver/0001-Hosts_Wildcards.patch"; #DnsResolver: Support wildcards in cached hosts file (tdm)
applyPatch "$DOS_PATCHES/android_packages_modules_DnsResolver/0002-hosts_toggle.patch"; #Add a toggle to disable /etc/hosts lookup (DivestOS)
applyPatch "$DOS_PATCHES/android_packages_modules_DnsResolver/0003-Reuse-align_ptr-in-hosts_cache.patch"; #Reuse align_ptr in hosts_cache (danielk43)
#applyPatch "$DOS_PATCHES/android_packages_modules_DnsResolver/0004-More-DoH.patch"; #Add more DoH endpoints (DivestOS)
fi;