From patchwork Thu Dec 7 19:16:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yauheni Kaliuta X-Patchwork-Id: 10100897 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6998A60325 for ; Thu, 7 Dec 2017 19:16:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5BB512860F for ; Thu, 7 Dec 2017 19:16:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 507B128658; Thu, 7 Dec 2017 19:16:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C31152860F for ; Thu, 7 Dec 2017 19:16:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751958AbdLGTQO (ORCPT ); Thu, 7 Dec 2017 14:16:14 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34644 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752346AbdLGTQN (ORCPT ); Thu, 7 Dec 2017 14:16:13 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F2B9F13A53; Thu, 7 Dec 2017 19:16:12 +0000 (UTC) Received: from astarta.redhat.com (ovpn-116-86.ams2.redhat.com [10.36.116.86]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3FC945C3F9; Thu, 7 Dec 2017 19:16:12 +0000 (UTC) From: Yauheni Kaliuta To: Lucas De Marchi Cc: linux-modules Subject: [PATCH 2/2] depmod: module_is_higher_priority: fix modname length calculation Date: Thu, 7 Dec 2017 21:16:08 +0200 Message-Id: <20171207191608.14293-3-yauheni.kaliuta@redhat.com> In-Reply-To: <20171207191608.14293-1-yauheni.kaliuta@redhat.com> References: <20171207191608.14293-1-yauheni.kaliuta@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 07 Dec 2017 19:16:13 +0000 (UTC) Sender: owner-linux-modules@vger.kernel.org Precedence: bulk List-ID: X-Virus-Scanned: ClamAV using ClamSMTP depmod_module_is_higher_priority checks module's path if it is under module root directory and if so uses relative to the root path to lookup the module in override and search lists. Originally only relative path was used in the function, so the variables with full path and and path length were changed: newpath += cfg->dirnamelen + 1; newlen -= cfg->dirnamelen + 1; oldpath += cfg->dirnamelen + 1; oldlen -= cfg->dirnamelen + 1; Commit 7da6884e7357ac05772e90f6d7e63b1948103fc4 (depmod: implement external directories support) changed the logic since it need the full path to the module for comparations as well. Unfortunately, it introduce a mistake in calculation of the relative paths replacing '-=' with assignment to a new variable -- the 'cfg->dirnamelen + 1' value must be substracted all together. It breaks, for example, overrides lookup. Fix the calculation by putting braces around the value in the subsctuction expression. Signed-off-by: Yauheni Kaliuta --- tools/depmod.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/depmod.c b/tools/depmod.c index 7ff3e9ed191e..921dc5cc93eb 100644 --- a/tools/depmod.c +++ b/tools/depmod.c @@ -1118,11 +1118,11 @@ static int depmod_module_is_higher_priority(const struct depmod *depmod, const s if (strncmp(newpath, cfg->dirname, cfg->dirnamelen) == 0) { relnewpath = newpath + cfg->dirnamelen + 1; - relnewlen = newlen - cfg->dirnamelen + 1; + relnewlen = newlen - (cfg->dirnamelen + 1); } if (strncmp(oldpath, cfg->dirname, cfg->dirnamelen) == 0) { reloldpath = oldpath + cfg->dirnamelen + 1; - reloldlen = oldlen - cfg->dirnamelen + 1; + reloldlen = oldlen - (cfg->dirnamelen + 1); } for (ov = cfg->overrides; ov != NULL; ov = ov->next) {