From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jeff Layton Subject: [PATCH v6 08/10] audit: make audit_compare_dname_path use parent_len helper Date: Fri, 7 Sep 2012 07:23:45 -0400 Message-ID: <1347017027-17167-9-git-send-email-jlayton@redhat.com> References: <1347017027-17167-1-git-send-email-jlayton@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mx1.redhat.com (ext-mx13.extmail.prod.ext.phx2.redhat.com [10.5.110.18]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q87BO6WL010310 for ; Fri, 7 Sep 2012 07:24:06 -0400 Received: from mail-vb0-f46.google.com (mail-vb0-f46.google.com [209.85.212.46]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q87BNseV008584 for ; Fri, 7 Sep 2012 07:24:05 -0400 Received: by mail-vb0-f46.google.com with SMTP id ff1so3620442vbb.33 for ; Fri, 07 Sep 2012 04:24:05 -0700 (PDT) In-Reply-To: <1347017027-17167-1-git-send-email-jlayton@redhat.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-audit-bounces@redhat.com Errors-To: linux-audit-bounces@redhat.com To: eparis@redhat.com, viro@zeniv.linux.org.uk Cc: linux-fsdevel@vger.kernel.org, bfields@fieldses.org, linux-audit@redhat.com, linux-kernel@vger.kernel.org List-Id: linux-audit@redhat.com From: Eric Paris Signed-off-by: Eric Paris --- kernel/auditfilter.c | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/kernel/auditfilter.c b/kernel/auditfilter.c index f9c48d0..f47ba18 100644 --- a/kernel/auditfilter.c +++ b/kernel/auditfilter.c @@ -1232,32 +1232,19 @@ int parent_len(const char *path) * return of 0 indicates a match. */ int audit_compare_dname_path(const char *dname, const char *path) { - int dlen, plen; + int dlen, pathlen, parentlen; const char *p; - if (!dname || !path) - return 1; - dlen = strlen(dname); - plen = strlen(path); - if (plen < dlen) + pathlen = strlen(path); + if (pathlen < dlen) return 1; - /* disregard trailing slashes */ - p = path + plen - 1; - while ((*p == '/') && (p > path)) - p--; - - /* find last path component */ - p = p - dlen + 1; - if (p < path) + parentlen = parent_len(path); + if (pathlen - parentlen != dlen) return 1; - else if (p > path) { - if (*--p != '/') - return 1; - else - p++; - } + + p = path + parentlen; return strncmp(p, dname, dlen); } -- 1.7.11.4