From owner-freebsd-bugs@FreeBSD.ORG Mon Mar 10 16:00:06 2008 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D02381065672 for ; Mon, 10 Mar 2008 16:00:06 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id BEC6B8FC1C for ; Mon, 10 Mar 2008 16:00:06 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.14.2/8.14.2) with ESMTP id m2AG06HD020499 for ; Mon, 10 Mar 2008 16:00:06 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.2/8.14.1/Submit) id m2AG06KG020494; Mon, 10 Mar 2008 16:00:06 GMT (envelope-from gnats) Resent-Date: Mon, 10 Mar 2008 16:00:06 GMT Resent-Message-Id: <200803101600.m2AG06KG020494@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, Ighighi Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E32091065671 for ; Mon, 10 Mar 2008 15:54:35 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21]) by mx1.freebsd.org (Postfix) with ESMTP id E3A348FC14 for ; Mon, 10 Mar 2008 15:54:35 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.14.2/8.14.2) with ESMTP id m2AFpNVL071098 for ; Mon, 10 Mar 2008 15:51:23 GMT (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.14.2/8.14.1/Submit) id m2AFpNfP071097; Mon, 10 Mar 2008 15:51:23 GMT (envelope-from nobody) Message-Id: <200803101551.m2AFpNfP071097@www.freebsd.org> Date: Mon, 10 Mar 2008 15:51:23 GMT From: Ighighi To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Cc: Subject: bin/121568: [patch]: wrong "ln -s" behaviour 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: Mon, 10 Mar 2008 16:00:06 -0000 >Number: 121568 >Category: bin >Synopsis: [patch]: wrong "ln -s" behaviour >Confidential: no >Severity: non-critical >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Mon Mar 10 16:00:01 UTC 2008 >Closed-Date: >Last-Modified: >Originator: Ighighi >Release: 6.3-STABLE >Organization: >Environment: FreeBSD orion 6.3-STABLE FreeBSD 6.3-STABLE #0: Mon Mar 3 04:45:31 VET 2008 root@orion:/usr/obj/usr/src/sys/CUSTOM i386 >Description: When running "ln -s" and the last argument is a directory, if any of the source files has a trailing slash it gives errors. To create a symlink like this: /tmp/defaults -> /etc/defaults/ $ /bin/rm -f /tmp/defaults $ /bin/ln -sv /etc/defaults/ /tmp ln: /tmp/: File exists $ /bin/ln -sv /etc/defaults /tmp /tmp/defaults -> /etc/defaults In this case, both commands should work regardless of any trailing slash, as is the case with GNU ln(1). I tend to use trailing slashes to make sure I'm hitting a directory or a symlink to one. Quoting the POSIX description of ln(1) available at: See http://www.opengroup.org/onlinepubs/009695399/utilities/ln.html "The corresponding destination path for each source_file shall be the concatenation of the target directory pathname, a slash character, and the last pathname component of the source_file. The second synopsis form shall be assumed when the final operand names an existing directory." The "last pathname component" is defined here: http://www.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap03.html#tag_03_267 The bug is in ln(1) using strrchr(xxx, '/') instead of basename(). >How-To-Repeat: >Fix: Attached patch tested against the latest code in CVS Patch attached with submission follows: --- src/bin/ln/ln.c.orig 2007-11-17 17:01:22.000000000 -0400 +++ src/bin/ln/ln.c 2008-03-10 04:52:27.703080785 -0430 @@ -46,6 +46,7 @@ #include #include +#include #include #include #include @@ -189,10 +190,8 @@ linkit(const char *source, const char *t if (isdir || (lstat(target, &sb) == 0 && S_ISDIR(sb.st_mode)) || (!hflag && stat(target, &sb) == 0 && S_ISDIR(sb.st_mode))) { - if ((p = strrchr(source, '/')) == NULL) - p = source; - else - ++p; + if ((p = basename(source)) == NULL) + return (1); if (snprintf(path, sizeof(path), "%s/%s", target, p) >= (ssize_t)sizeof(path)) { errno = ENAMETOOLONG; >Release-Note: >Audit-Trail: >Unformatted: