From owner-freebsd-bugs@FreeBSD.ORG Fri Aug 25 18:50:24 2006 Return-Path: X-Original-To: freebsd-bugs@hub.freebsd.org Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 168FB16A4DE for ; Fri, 25 Aug 2006 18:50:24 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 87C9143D49 for ; Fri, 25 Aug 2006 18:50:23 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.4/8.13.4) with ESMTP id k7PIoN5T028195 for ; Fri, 25 Aug 2006 18:50:23 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.4/8.13.4/Submit) id k7PIoNTh028194; Fri, 25 Aug 2006 18:50:23 GMT (envelope-from gnats) Resent-Date: Fri, 25 Aug 2006 18:50:23 GMT Resent-Message-Id: <200608251850.k7PIoNTh028194@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Jin Guojun Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 642B616A4DA for ; Fri, 25 Aug 2006 18:43:56 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (www.freebsd.org [216.136.204.117]) by mx1.FreeBSD.org (Postfix) with ESMTP id AB9E143D6D for ; Fri, 25 Aug 2006 18:43:55 +0000 (GMT) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.13.1/8.13.1) with ESMTP id k7PIhtgF092958 for ; Fri, 25 Aug 2006 18:43:55 GMT (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.13.1/8.13.1/Submit) id k7PIhtBo092957; Fri, 25 Aug 2006 18:43:55 GMT (envelope-from nobody) Message-Id: <200608251843.k7PIhtBo092957@www.freebsd.org> Date: Fri, 25 Aug 2006 18:43:55 GMT From: Jin Guojun To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-2.3 Cc: Subject: bin/102510: diff should not follow symlink in recursive (-r) mode X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 25 Aug 2006 18:50:24 -0000 >Number: 102510 >Category: bin >Synopsis: diff should not follow symlink in recursive (-r) mode >Confidential: no >Severity: serious >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Fri Aug 25 18:50:18 GMT 2006 >Closed-Date: >Last-Modified: >Originator: Jin Guojun >Release: All FreeBSD release >Organization: >Environment: Non hardware related issue >Description: /usr/bin/diff should not follow symlink in recursive mode (with option "-r"). Where "-r" option is used to compare two structures/trees, where one of them is a mirror or duplication of the other. It is not clear what is the historical reason "diff -r" follows symlink in this mode. It is hardly to see "diff -r" may be used to compare two completely different file structure or trees. Therefore, to compare two same/similar file trees, there is no any good reason to follow the symlink for diffing. If the node at the end of the link exists, it will be compared eventually anyway. If the symlink points to nowhere, then there is no meaning to follow it. It wastes time to follow symlink to do number of extra comparisons. Also, if user(s) create some long-multi-path links between directories/trees, diff -r will loop forever (no infinit, but may take a day) in comparing such file trees. >How-To-Repeat: I have send a simple example to hackers for comment, but have not heard any feedback. It can be found in mailing archive. The real problem on a large file tree/structure may take time to debug. However, it is not hard to see the problem through above description. A patch is provide to disable the feature of following symlink in "-r" mode. Since the patch is copy/pasted, it may not be directly applied via "patch", but it is very simple (tree line added, and one line changed), so manually apply it is easy. When I receive the reply,I will send the patch in via email if people agree this patch. If for some reason following symlink is needed in "-r" mode, then a switch (option) can be added for such purpose to enable following symlink feature in "-r" recursive mode. >Fix: *** /usr/src/contrib/diff/diff.c.orig Tue Aug 15 14:05:30 2006 --- /usr/src/contrib/diff/diff.c Tue Aug 15 14:04:45 2006 *************** *** 832,837 **** --- 832,840 ---- /* other popular file types */ /* S_ISLNK is impossible with `fstat' and `stat'. */ + #ifdef S_ISLNK + if (S_ISLNK (st->st_mode)) return "symlink"; + #endif #ifdef S_ISSOCK if (S_ISSOCK (st->st_mode)) return "socket"; #endif *************** *** 927,933 **** } } else ! stat_result = stat (inf[i].name, &inf[i].stat); if (stat_result != 0) { --- 930,936 ---- } } else ! stat_result = (recursive ? lstat : stat) (inf[i].name, &inf[i].stat) ; if (stat_result != 0) { >Release-Note: >Audit-Trail: >Unformatted: