Received: from list by lists.gnu.org with archive (Exim 4.71) id 1cVsCq-0001X8-8M for mharc-grub-devel@gnu.org; Mon, 23 Jan 2017 22:55:40 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34503) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cVsCo-0001X1-Mk for grub-devel@gnu.org; Mon, 23 Jan 2017 22:55:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cVsCl-0006y8-Db for grub-devel@gnu.org; Mon, 23 Jan 2017 22:55:38 -0500 Received: from mail-lf0-x244.google.com ([2a00:1450:4010:c07::244]:33548) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cVsCl-0006wP-6d for grub-devel@gnu.org; Mon, 23 Jan 2017 22:55:35 -0500 Received: by mail-lf0-x244.google.com with SMTP id x1so15644821lff.0 for ; Mon, 23 Jan 2017 19:55:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=1LpsN7WZCHjwhOel+7bBW5SjeqnMfrtWO79tm8/Gmk4=; b=ayA+r5ncYN5a1UxhrCvAfKTtfL9ep0SqAzTn6YtVWgtte5bMSqnJeiFVSVo+YB2NOJ kDhqA943Emwp3XT0/5xj1DO0oVoWci4O5t5RUBiPpuIvPWVDqRNVOOfaqvTsPsl23U85 he3q/RkO0ykoYWHaP6A79rgs/IXgLvzKfYrMpZctDuMCORAfvpibyad9pVaJ7ePx5iee GKdjL647Fs+J+PQKl9gV7gBPF4eMrR9LffZv5U45bjqz29zU0Vx/83/5AQKycY3KH1VR 5yU4fZgMMqG53NfakF0lETel2w0SrP9nGQEFYIx5udWXGAz2DqBui0j6nT7NwM+QI9YB sDXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=1LpsN7WZCHjwhOel+7bBW5SjeqnMfrtWO79tm8/Gmk4=; b=CzNYAvcZpMo4aZj7p1WxDxRttPJB+8XGWBcW/qvK9h6PMotQ5akP5axmc8Yxg82drG ICGGiDhIfc1DTtUtpXylZFatHgLAMBkkaqLhyn6gHdG06xiVNU/W4RlpbGweD3z0nDJq l1c7ciGa7KJmIdM9HS9W0Y5cgFHQqqpadK/u/+FUInVEpeEqaWMNFWL6eurHbA8OGlxO TbMuXj9bCIeHrDD8zqlTJ3zmymrXW4Gw+3GDfkK6zgNH5DBXabQ/7YE8kjtkE3KkjwkN Xe58sH+g96LdMwECIDoIUnio98BBMdX9wHg3/JiUdXXSbcbkC9Ri+YFU3jmhwnVZtZz2 XzQw== X-Gm-Message-State: AIkVDXItI/HtILifdocCfpz6yGZJ++koiz2lM715BQidbgYNTBvQ2vqwqIZ1jMADVhO62Q== X-Received: by 10.25.242.79 with SMTP id d15mr4599431lfk.22.1485230132179; Mon, 23 Jan 2017 19:55:32 -0800 (PST) Received: from [192.168.1.3] (ppp109-252-90-129.pppoe.spdop.ru. [109.252.90.129]) by smtp.gmail.com with ESMTPSA id l67sm6869691lfb.15.2017.01.23.19.55.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Jan 2017 19:55:31 -0800 (PST) Subject: Re: [PATCH 3/4] Don't allocate a new address buffer if we receive multiple DNS responses To: The development of GNU GRUB References: <20170124003601.24612-1-mjg59@coreos.com> <20170124003601.24612-4-mjg59@coreos.com> Cc: Matthew Garrett From: Andrei Borzenkov Message-ID: <71fb5b8f-0e1c-f6ca-0a85-200f60695268@gmail.com> Date: Tue, 24 Jan 2017 06:55:30 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 In-Reply-To: <20170124003601.24612-4-mjg59@coreos.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:4010:c07::244 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 24 Jan 2017 03:55:39 -0000 24.01.2017 03:36, Matthew Garrett пишет: > The current logic in the DNS resolution code allocates an address buffer > based on the number of addresses in the response packet. If we receive > multiple response packets in response to a single query packet, this means > that we will reallocate a new buffer large enough for only the addresses in > that specific packet, discarding any previous results in the process. Worse, > we still keep track of the *total* number of addresses resolved in response > to this query, not merely the number in the packet being currently processed. > Use realloc() rather than malloc() to avoid overwriting the existing data, > and allocate a buffer large enough for the total set of addresses rather > than merely the number in this specific response. > --- > grub-core/net/dns.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/grub-core/net/dns.c b/grub-core/net/dns.c > index 5d9afe0..5deb1ef 100644 > --- a/grub-core/net/dns.c > +++ b/grub-core/net/dns.c > @@ -285,8 +285,8 @@ recv_hook (grub_net_udp_socket_t sock __attribute__ ((unused)), > ptr++; > ptr += 4; > } > - *data->addresses = grub_malloc (sizeof ((*data->addresses)[0]) > - * grub_be_to_cpu16 (head->ancount)); > + *data->addresses = grub_realloc (*data->addresses, sizeof ((*data->addresses)[0]) > + * (grub_be_to_cpu16 (head->ancount) + *data->naddresses)); If *data->addresses was not NULL, we should not reach this code. /* Code apparently assumed that only one packet is received as response. We may get multiple responses due to network condition, so check here and quit early. */ if (*data->addresses) { grub_netbuff_free (nb); return GRUB_ERR_NONE; } This was noted previously by Josef, we discussed it and my position is that resolver code requires redesign to correctly merge multiple answers and prioritize A vs AAAA requests. Do you get actual errors with current master? If yes, could you provide more information what this patch fixes? > if (!*data->addresses) > { > grub_errno = GRUB_ERR_NONE; >