From 56e9a75445afea63f3d3d23164047563843fd6e0 Mon Sep 17 00:00:00 2001 From: Tad Date: Sun, 5 Sep 2021 16:30:34 -0400 Subject: [PATCH] 14.1+15.1: Support wildcards in cached hosts file Signed-off-by: Tad --- .../android_bionic/0001-Wildcard_Hosts.patch | 69 +++++++++++++++++++ Scripts/LineageOS-14.1/Patch.sh | 4 ++ Scripts/LineageOS-15.1/Patch.sh | 4 ++ 3 files changed, 77 insertions(+) create mode 100644 Patches/Common/android_bionic/0001-Wildcard_Hosts.patch diff --git a/Patches/Common/android_bionic/0001-Wildcard_Hosts.patch b/Patches/Common/android_bionic/0001-Wildcard_Hosts.patch new file mode 100644 index 00000000..e8ea8c47 --- /dev/null +++ b/Patches/Common/android_bionic/0001-Wildcard_Hosts.patch @@ -0,0 +1,69 @@ +From 8604fcb3686a74d8f2a0632027525486febd45a4 Mon Sep 17 00:00:00 2001 +From: Tom Marshall +Date: Thu, 16 Jan 2020 13:07:04 -0800 +Subject: [PATCH] bionic: Support wildcards in cached hosts file + +If an exact name is not found in the hosts file and the host name +contains at least one dot, search for entries of the form "*.domain", +where domain is the portion of the host name after the first dot. If +that is not found, repeat using the domain. + +Example: a.b.c.example.com would search for the following in turn: + a.b.c.example.com + *.b.c.example.com + *.c.example.com + *.example.com + *.com + +Change-Id: I4b0bb81699151d5b371850daebf785e35ec9b180 +--- + libc/dns/net/hosts_cache.c | 29 ++++++++++++++++++++++++++++- + 1 file changed, 28 insertions(+), 1 deletion(-) + +diff --git a/libc/dns/net/hosts_cache.c b/libc/dns/net/hosts_cache.c +index deafb78b73..5038986be6 100644 +--- a/libc/dns/net/hosts_cache.c ++++ b/libc/dns/net/hosts_cache.c +@@ -121,7 +121,7 @@ static int cmp_hcent_name(const void *a, const void *b) + return hstrcmp(na, nb); + } + +-static struct hcent *_hcfindname(const char *name) ++static struct hcent *_hcfindname_exact(const char *name) + { + size_t first, last, mid; + struct hcent *cur = NULL; +@@ -162,6 +162,33 @@ static struct hcent *_hcfindname(const char *name) + return cur; + } + ++static struct hcent *_hcfindname(const char *name) ++{ ++ struct hcent *ent; ++ char namebuf[MAX_HOSTLEN]; ++ char *p; ++ char *dot; ++ ++ ent = _hcfindname_exact(name); ++ if (!ent && strlen(name) < sizeof(namebuf)) { ++ strcpy(namebuf, name); ++ p = namebuf; ++ do { ++ dot = strchr(p, '.'); ++ if (!dot) ++ break; ++ if (dot > p) { ++ *(dot - 1) = '*'; ++ ent = _hcfindname_exact(dot - 1); ++ } ++ p = dot + 1; ++ } ++ while (!ent); ++ } ++ ++ return ent; ++} ++ + /* + * Find next name on line, if any. + * diff --git a/Scripts/LineageOS-14.1/Patch.sh b/Scripts/LineageOS-14.1/Patch.sh index 042cbea9..eab95c0c 100644 --- a/Scripts/LineageOS-14.1/Patch.sh +++ b/Scripts/LineageOS-14.1/Patch.sh @@ -54,6 +54,10 @@ gpgVerifyDirectory "$DOS_PREBUILT_APPS""android_vendor_FDroid_PrebuiltApps/packa cp -r "$DOS_PREBUILT_APPS""android_vendor_FDroid_PrebuiltApps/." "$DOS_BUILD_BASE""vendor/fdroid_prebuilt/"; #Add the prebuilt apps cp -r "$DOS_PATCHES_COMMON""android_vendor_divested/." "$DOS_BUILD_BASE""vendor/divested/"; #Add our vendor files +if enterAndClear "bionic"; then +patch -p1 < "$DOS_PATCHES_COMMON/android_bionic/0001-Wildcard_Hosts.patch"; #Support wildcards in cached hosts file (backport from 16.0+) +fi; + if enterAndClear "bootable/recovery"; then git revert --no-edit 3c0d796b79c7a1ee904e0cef7c0f2e20bf84c237; #Remove sideload cache, breaks with large files patch -p1 < "$DOS_PATCHES/android_bootable_recovery/0001-Squash_Menus.patch"; #What's a back button? diff --git a/Scripts/LineageOS-15.1/Patch.sh b/Scripts/LineageOS-15.1/Patch.sh index b4287bfb..8cfc8195 100644 --- a/Scripts/LineageOS-15.1/Patch.sh +++ b/Scripts/LineageOS-15.1/Patch.sh @@ -51,6 +51,10 @@ gpgVerifyDirectory "$DOS_PREBUILT_APPS""android_vendor_FDroid_PrebuiltApps/packa cp -r "$DOS_PREBUILT_APPS""android_vendor_FDroid_PrebuiltApps/." "$DOS_BUILD_BASE""vendor/fdroid_prebuilt/"; #Add the prebuilt apps cp -r "$DOS_PATCHES_COMMON""android_vendor_divested/." "$DOS_BUILD_BASE""vendor/divested/"; #Add our vendor files +if enterAndClear "bionic"; then +patch -p1 < "$DOS_PATCHES_COMMON/android_bionic/0001-Wildcard_Hosts.patch"; #Support wildcards in cached hosts file (backport from 16.0+) +fi; + if enterAndClear "bootable/recovery"; then git revert --no-edit eb98fde70a6e54a25408eb8c626caecf7841c5df; #Remove sideload cache, breaks with large files git revert --no-edit ac258a4f4c4b4b91640cc477ad1ac125f206db02; #Resurrect dm-verity