summaryrefslogtreecommitdiff
path: root/src/resolve/resolved-etc-hosts.h
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2022-05-19 10:38:27 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2022-05-20 15:18:28 +0200
commiteb164c51eab0d397f2e1370c7cbfd480877f28a0 (patch)
tree12c8f25cf4af79a0ac70170928fc131c2d5ee5db /src/resolve/resolved-etc-hosts.h
parent3ec3ae68d2cea32461d779645a737d57160631bf (diff)
downloadsystemd-eb164c51eab0d397f2e1370c7cbfd480877f28a0.tar.gz
resolved: use strv_extend_with_size() to avoid slow parsing of /etc/hosts
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=43942 is a simple case where a repeated entry generates a timeout. I didn't import that case, but generated a simpler one by hand. $ time build/fuzz-etc-hosts test/fuzz/fuzz-etc-hosts/timeout-many-entries test/fuzz/fuzz-etc-hosts/timeout-many-entries... ok build/fuzz-etc-hosts test/fuzz/fuzz-etc-hosts/timeout-many-entries 3.17s (old) ↓ build/fuzz-etc-hosts test/fuzz/fuzz-etc-hosts/timeout-many-entries 0.11s (new) I considered simply disallowing too many aliases. E.g. microsoft appearently sometimes ignores entries after the ninth [1], and other systems set stringent limits [2,3], but the recommended way to get around that is to simply use more lines (as is done in the sample), so this wouldn't change anything. Even if we cannot put all those names in a reply packet, the resolution from the alias to the address should work. I think cases where people define lots and lots of aliases through some programmatic interface is realistic, for example for a blocklist, and such a file shouldn't bring resolved down to its knees. [1] https://superuser.com/questions/932112/is-there-a-maximum-number-of-hostname-aliases-per-line-in-a-windows-hosts-file [2] https://library.netapp.com/ecmdocs/ECMP1516135/html/GUID-C6F3B6D1-232D-44BB-A76C-3304C19607A3.html [3] https://www.ibm.com/docs/en/zos/2.1.0?topic=optional-creating-etchosts
Diffstat (limited to 'src/resolve/resolved-etc-hosts.h')
-rw-r--r--src/resolve/resolved-etc-hosts.h1
1 files changed, 1 insertions, 0 deletions
diff --git a/src/resolve/resolved-etc-hosts.h b/src/resolve/resolved-etc-hosts.h
index c85926a3dc..df66e714da 100644
--- a/src/resolve/resolved-etc-hosts.h
+++ b/src/resolve/resolved-etc-hosts.h
@@ -9,6 +9,7 @@ typedef struct EtcHostsItem {
struct in_addr_data address;
char **names;
+ size_t n_names;
} EtcHostsItem;
typedef struct EtcHostsItemByName {