From eb164c51eab0d397f2e1370c7cbfd480877f28a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 19 May 2022 10:38:27 +0200 Subject: resolved: use strv_extend_with_size() to avoid slow parsing of /etc/hosts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/resolve/resolved-etc-hosts.h | 1 + 1 file changed, 1 insertion(+) (limited to 'src/resolve/resolved-etc-hosts.h') 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 { -- cgit v1.2.1