From patchwork Wed Apr 17 17:52:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick McDermott X-Patchwork-Id: 1087101 X-Patchwork-Delegate: ynezz@true.cz Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) 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=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=libiquity.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="X7m3Dmq8"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44kqnK5fjlz9s4Y for ; Thu, 18 Apr 2019 04:01:57 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Subject:Message-Id: Date:To:From: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=62rji4k14cnxGS7oSOVikwNuGXOWk+0xVpcySAOrHdo=; b=X7m3Dmq840lqA9 jG7l9bvJ7zQx+GtPBvdznJYlB0RLkGov7iJlRwigCK3FkL7MPJTXppb9V2Dv1iyiRvp/wvUOPEgib Ryg2vZ0PeCYTcnZtfyvRMtGaUrKeJDx7kHL5lYcRPwH8uTNj1ime+caqr5hGVTG0rUTwWrkcxAemt /syi/WXnrH2W6GHwNWLCTeL/P0u3J9wZP3rPSTWVBNMFmoqit1gFtYE2Jm43uycmgKV6jKUTsAl9t /L77N0z1rOmfVyrkjLuPeQmt46Knk2/vo5SGVJYaY8DZcUtVlu8037MBCGrxk4Hzac2sDT0WKWk3g mtinonhWkjawFtyX33Hw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGosT-0002NW-7E; Wed, 17 Apr 2019 18:01:45 +0000 Received: from lib1.libiquity.com ([24.229.5.118]) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGosP-0002N8-Vh for openwrt-devel@lists.openwrt.org; Wed, 17 Apr 2019 18:01:43 +0000 Received: from localhost.localdomain (unknown [24.229.5.114]) by lib1.libiquity.com (Postfix) with ESMTP id 556ADC074E; Wed, 17 Apr 2019 13:53:35 -0400 (EDT) From: Patrick McDermott To: Jo-Philipp Wich Date: Wed, 17 Apr 2019 13:52:29 -0400 Message-Id: <20190417175229.1333-1-patrick.mcdermott@libiquity.com> X-Mailer: git-send-email 2.11.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190417_110142_112722_89AF0CC4 X-CRM114-Status: UNSURE ( 5.64 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.0 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record Subject: [OpenWrt-Devel] [PATCH][opkg-lede] libopkg: Fix segfault on trailing comma in deps X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: openwrt-devel@lists.openwrt.org, Patrick McDermott MIME-Version: 1.0 Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org A "Depends" or other package relationship field with a trailing comma (followed by zero or more whitespace characters) in any package feed list will cause opkg after commit 98ce8c2 ("pkg: convert most other struct members into dynamic blob buffer fields") to segfault. In the case of a trailing comma, parseDepends() has always been called with a string containing only the whitespace (if any) following the comma, and previously a copy loop extracted the dependency package name as an empty string. Now, strtok() returns NULL as the package name, which is passed through ensure_abstract_pkg_by_name(), abstract_pkg_fetch_by_name(), hash_table_get(), hash_index(), and finally djb2_hash() which dereferences the NULL pointer. Signed-off-by: Patrick McDermott --- libopkg/pkg_depends.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libopkg/pkg_depends.c b/libopkg/pkg_depends.c index 3abdcd3..6d075f2 100644 --- a/libopkg/pkg_depends.c +++ b/libopkg/pkg_depends.c @@ -1025,6 +1025,8 @@ static int parseDepends(compound_depend_t * compound_depend, char *depend_str, e for (i = 0, depend = strtok_r(depend_str, "|", &tok); depend; i++, depend = strtok_r(NULL, "|", &tok)) { name = strtok(depend, " "); + if (!name) + break; rest = strtok(NULL, "\n"); tmp = realloc(possibilities, sizeof(tmp) * (i + 1));