From owner-freebsd-bugs Wed Sep 4 10:30:14 2002 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 89A7E37B405 for ; Wed, 4 Sep 2002 10:30:03 -0700 (PDT) Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id EBDD443E6A for ; Wed, 4 Sep 2002 10:30:02 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.4/8.12.4) with ESMTP id g84HU2JU098286 for ; Wed, 4 Sep 2002 10:30:02 -0700 (PDT) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.4/8.12.4/Submit) id g84HU2pW098285; Wed, 4 Sep 2002 10:30:02 -0700 (PDT) Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id A9FAE37B400 for ; Wed, 4 Sep 2002 10:21:33 -0700 (PDT) Received: from melusine.cuivre.fr.eu.org (melusine.cuivre.fr.eu.org [62.212.105.185]) by mx1.FreeBSD.org (Postfix) with ESMTP id 1AA2843E6A for ; Wed, 4 Sep 2002 10:21:33 -0700 (PDT) (envelope-from thomas@cuivre.fr.eu.org) Received: by melusine.cuivre.fr.eu.org (Postfix, from userid 1000) id 077722C3D1; Wed, 4 Sep 2002 19:21:32 +0200 (CEST) Message-Id: <20020904172132.077722C3D1@melusine.cuivre.fr.eu.org> Date: Wed, 4 Sep 2002 19:21:32 +0200 (CEST) From: Thomas Quinot Reply-To: Thomas Quinot To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Subject: bin/42418: [patch] perl wrapper loops on itself Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org >Number: 42418 >Category: bin >Synopsis: [patch] perl wrapper loops on itself >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: Wed Sep 04 10:30:02 PDT 2002 >Closed-Date: >Last-Modified: >Originator: Thomas Quinot >Release: FreeBSD 5.0-CURRENT i386 >Organization: >Environment: System: FreeBSD shalmaneser.enst.fr 5.0-CURRENT FreeBSD 5.0-CURRENT #1: Tue Sep 3 14:05:44 CEST 2002 root@shalmaneser.enst.fr:/usr/obj/usr/src/sys/SHALMANESER i386 >Description: When PATH contains a symbolic link to /usr/bin/perl (typically, a /usr/local/bin/perl link that used to point the the base system perl), the wrapper loops on itself. >How-To-Repeat: mkdir /tmp/foo PATH=/tmp/foo:$PATH ln -s /usr/bin/perl /tmp/foo /usr/bin/perl # will loop forever >Fix: The proposed solution is to make the wrapper stat the files it is considering as candidate real interpreter, and skip itself. Patch included. Index: perl.c =================================================================== RCS file: /home/ncvs/src/usr.bin/perl/perl.c,v retrieving revision 1.4 diff -u -r1.4 perl.c --- perl.c 21 Aug 2002 20:54:45 -0000 1.4 +++ perl.c 4 Sep 2002 17:21:11 -0000 @@ -30,6 +30,7 @@ __FBSDID("$FreeBSD: src/usr.bin/perl/perl.c,v 1.4 2002/08/21 20:54:45 joerg Exp $"); #include +#include #include #include @@ -49,8 +50,13 @@ char path[PATH_MAX], *cp; const char *cmd, *p, *q, *self; size_t len; + struct stat self_stat, perl_stat; self = argv[0]; + if (stat (self, &self_stat) != 0) { + self_stat.st_dev = makedev (0, 0); + self_stat.st_ino = 0; + } if ((cmd = strrchr(self, '/')) == NULL) cmd = self; else @@ -78,6 +84,10 @@ /* nothing */ ; len = snprintf(path, sizeof path, "%.*s/%s", (int)(q - p), p, cmd); if (len >= PATH_MAX || strcmp(path, self) == 0) + continue; + if (stat (path, &perl_stat) == 0 + && self_stat.st_dev == perl_stat.st_dev + && self_stat.st_ino == perl_stat.st_ino) continue; execve(path, argv, environ); if (errno != ENOENT) >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message