From patchwork Fri Jan 21 11:37:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: MRoeder@metz-connect.com X-Patchwork-Id: 1582553 X-Patchwork-Delegate: daniel@makrotopia.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=ImgPfJgE; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JgHVR1HCYz9t2p for ; Fri, 21 Jan 2022 22:39:58 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Date:From:Message-ID:Subject: MIME-Version:Cc:To:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=b2MtdbbD2YMexqNJ7pzDzpxYWOV5H2i/WYXti5jGoxY=; b=Img PfJgExL9mjQ7iQhjWS3cC8LoavNQ9/TxFypw/7ByBxC6OS5oUayaHvy70ljohQfb3f1OqpA4yWyiH qEyfa3YQKeKx/u7m3vs4h1Kgk10AByA0LyFm9OGKCNa4EmkSOSjzfoDiYKeAJhXygx4PzeymoQFXP vZiamESzCMjicHI8ZscWXxqOe+S0n+7K6gEYgAcl7BhV+MOqORoKUKKz6aZIhysB7SZ/jVyLtRl7q Naz1HpplV7HCU1g74wMG2/biQFo80/5qcCnc2vVrWYCt8SbBFEJI4HywsYf6ZF0XYv+QBWooUrOYl qOCMEUh9OPt55F7YycH5B2QGDbO0j+w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nAsES-00EoZw-9S; Fri, 21 Jan 2022 11:37:28 +0000 Received: from mail.ria-btr.de ([217.7.162.42]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nAsEO-00EoZI-3L for openwrt-devel@lists.openwrt.org; Fri, 21 Jan 2022 11:37:26 +0000 Received: from svadsw102.metzconnect.local ( [10.10.0.1]) by mail.ria-btr.de (Reddoxx engine) with SMTP id 61E3400F1A3; Fri, 21 Jan 2022 12:37:16 +0100 To: John Crispin Cc: openwrt-devel@lists.openwrt.org MIME-Version: 1.0 Subject: [PATCH] Bugfix for OpenWrt package umdns X-KeepSent: 74C0E29A:86D43F23-C12587D1:003DAB67; type=4; name=$KeepSent X-Mailer: IBM Notes Release 9.0.1 October 14, 2013 Message-ID: From: MRoeder@metz-connect.com Date: Fri, 21 Jan 2022 12:37:14 +0100 X-MIMETrack: Serialize by Router on SVDOMW101/FAM(Release 9.0.1FP5|November 22, 2015) at 21.01.2022 12:37:16, Serialize complete at 21.01.2022 12:37:16 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220121_033724_502113_66BB7968 X-CRM114-Status: UNSURE ( 8.74 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.0 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Hi John, I would like to submit a patch for the OpenWrt package umdns. The patch fixes a bug in the cache.c functions cache_record_find() and cache_host_is_known(). In both functions, the last element of the A [...] Content analysis details: (-0.0 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org Hi John, I would like to submit a patch for the OpenWrt package umdns. The patch fixes a bug in the cache.c functions cache_record_find() and cache_host_is_known(). In both functions, the last element of the AVL tree is systematically missed, which can lead to duplicate cache entries and lookup failures. The fix duplicates the correct AVL tree traversal approach of cache_dump_recursive(). PS: Appologies if this message has format issues. This is my first attempt to submit a patch to OpenWrt through our company IBM Notes infrastructure, please let me know if the message format is unsuitable. Best regards, Martin -------------------------------- Fix AVL tree traversal in cache_record_find() and cache_host_is_known(): The AVL tree traversal in both functions systematically misses the last AVL tree element. This can lead to duplicate cache entries and lookup failures. The fix duplicates the correct AVL tree traversal approach of cache_dump_recursive(). Signed-off-by: Martin Röder if (r->type != type) continue; @@ -227,13 +224,10 @@ cache_host_is_known(char *record) { struct cache_record *l = avl_find_element(&records, record, l, avl); - if (!l) - return 0; - - while (l && !avl_is_last(&records, &l->avl) && !strcmp(l->record, record)) { + while (l && !strcmp(l->record, record)) { struct cache_record *r = l; - l = avl_next_element(l, avl); + l = !avl_is_last(&records, &l->avl) ? avl_next_element(l, avl) : NULL; if ((r->type != TYPE_A) && (r->type != TYPE_AAAA)) continue; return 1; --- a/cache.c +++ b/cache.c @@ -191,13 +191,10 @@ cache_record_find(char *record, int type { struct cache_record *l = avl_find_element(&records, record, l, avl); - if (!l) - return NULL; - - while (l && !avl_is_last(&records, &l->avl) && !strcmp(l->record, record)) { + while (l && !strcmp(l->record, record)) { struct cache_record *r = l; - l = avl_next_element(l, avl); + l = !avl_is_last(&records, &l->avl) ? avl_next_element(l, avl) : NULL;