NetBSD Problem Report #52295

From www@NetBSD.org  Tue Jun 13 09:07:49 2017
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "mail.netbsd.org", Issuer "Postmaster NetBSD.org" (verified OK))
	by mollari.NetBSD.org (Postfix) with ESMTPS id B87F67A210
	for <gnats-bugs@gnats.NetBSD.org>; Tue, 13 Jun 2017 09:07:49 +0000 (UTC)
Message-Id: <20170613090748.C2A337A2A5@mollari.NetBSD.org>
Date: Tue, 13 Jun 2017 09:07:48 +0000 (UTC)
From: tho@netbsd.org
Reply-To: tho@netbsd.org
To: gnats-bugs@NetBSD.org
Subject: find -delete: "relative path not safe" with absolute paths ...
X-Send-Pr-Version: www-1.0

>Number:         52295
>Category:       bin
>Synopsis:       find -delete: "relative path not safe" with absolute paths ...
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    bin-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Jun 13 09:10:00 +0000 2017
>Closed-Date:    Thu Aug 17 18:56:08 +0000 2017
>Last-Modified:  Thu Aug 17 18:56:08 +0000 2017
>Originator:     Anthony Mallet
>Release:        NetBSD 7.0.1,  7.99.75 -current as well
>Organization:
>Environment:
NetBSD fluffy64-netbsd7 7.0.1 NetBSD 7.0.1 (FLUFFY) #0: Tue Jun  7 14:30:24 CEST 2016  root@fluffy64-netbsd6:/usr/obj/sys/arch/amd64/compile/FLUFFY amd64

>Description:
/usr/bin/find /<path> -delete raises an error when given an absolute path.

This happens in usr.bin/find/function.c:467
/* Potentially unsafe - do not accept relative paths whatsoever */      
if (strchr(entry->fts_accpath, '/') != NULL)                            
        errx(1, "-delete: %s: relative path potentially not safe",      
                entry->fts_accpath);

I understand that the intent is to filter out slashes from anything that `find` would append to the user input <path>, however this is getting in the way in this case :)

>How-To-Repeat:
$ which find
/usr/bin/find
$ mkdir /tmp/test
$ find /tmp/test -delete
find: -delete: /tmp/test: relative path potentially not safe
$

While this is fine:
$ cd /tmp/test
$ find . -delete
$

>Fix:

>Release-Note:

>Audit-Trail:
From: "Anthony Mallet" <mallet@laas.fr>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: bin/52295: find -delete: "relative path not safe" with absolute paths ...
Date: Tue, 13 Jun 2017 14:30:27 +0200

 OpenBSD seems to not have the issue. Here is a fix (from their code):

 Index: usr.bin/find/function.c
 ===================================================================
 RCS file: /cvsroot/src/usr.bin/find/function.c,v
 retrieving revision 1.72
 diff -u -r1.72 function.c
 --- usr.bin/find/function.c     4 May 2013 06:29:32 -0000       1.72
 +++ usr.bin/find/function.c     13 Jun 2017 12:29:17 -0000
 @@ -374,7 +374,8 @@
                 errx(1, "-delete: insecure options got turned on");

         /* Potentially unsafe - do not accept relative paths whatsoever */
 -       if (strchr(entry->fts_accpath, '/') != NULL)
 +       if (entry->fts_level > 0 &&
 +           strchr(entry->fts_accpath, '/') != NULL)
                 errx(1, "-delete: %s: relative path potentially not safe",
                         entry->fts_accpath);

From: "Christos Zoulas" <christos@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/52295 CVS commit: src/usr.bin/find
Date: Tue, 13 Jun 2017 09:10:32 -0400

 Module Name:	src
 Committed By:	christos
 Date:		Tue Jun 13 13:10:32 UTC 2017

 Modified Files:
 	src/usr.bin/find: function.c

 Log Message:
 PR/52295: Anthony Mallet: find -delete: "relative path not safe" with absolute
 paths ... Fix from OpenBSD


 To generate a diff of this commit:
 cvs rdiff -u -r1.75 -r1.76 src/usr.bin/find/function.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Anthony Mallet" <mallet@laas.fr>
To: gnats-bugs@NetBSD.org
Cc: "Christos Zoulas" <christos@netbsd.org>
Subject: PR/52295 CVS commit: src/usr.bin/find
Date: Tue, 13 Jun 2017 18:07:45 +0200

 On Tuesday 13 Jun 2017, at 13:15, Christos Zoulas wrote:
 > Subject: PR/52295 CVS commit: src/usr.bin/find
 > Date: Tue, 13 Jun 2017 09:10:32 -0400

 Thanks!
 Could it be pulled to netbsd-8, too?

State-Changed-From-To: open->pending-pullups
State-Changed-By: maya@NetBSD.org
State-Changed-When: Wed, 14 Jun 2017 11:32:35 +0000
State-Changed-Why:
pullup-8 #40


From: "Soren Jacobsen" <snj@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/52295 CVS commit: [netbsd-8] src/usr.bin/find
Date: Thu, 15 Jun 2017 05:46:49 +0000

 Module Name:	src
 Committed By:	snj
 Date:		Thu Jun 15 05:46:49 UTC 2017

 Modified Files:
 	src/usr.bin/find [netbsd-8]: function.c

 Log Message:
 Pull up following revision(s) (requested by christos in ticket #40):
 	usr.bin/find/function.c: revision 1.76
 PR/52295: Anthony Mallet: find -delete: "relative path not safe" with absolute
 paths ... Fix from OpenBSD


 To generate a diff of this commit:
 cvs rdiff -u -r1.75 -r1.75.8.1 src/usr.bin/find/function.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: pending-pullups->closed
State-Changed-By: jdolecek@NetBSD.org
State-Changed-When: Thu, 17 Aug 2017 18:56:08 +0000
State-Changed-Why:
Pullup to netbsd-8 done. Thank you.


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2014 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.