From cf69565b5f5f60354e70b2fb8009da43de22c1ff Mon Sep 17 00:00:00 2001 From: thomas Date: Tue, 10 Sep 2002 13:56:30 +0000 Subject: Prevent the wrapper from looping on itself forever, when there is a symbolic link in the PATH pointing back to /usr/bin/perl. Change WARNS from 6 to 5 to account for the fact that sys/time.h, included from sys/stat.h, produces a warning when compiled with -pedantic. PR: bin/42418 Reviewed by: roberto --- usr.bin/perl/Makefile | 2 +- usr.bin/perl/perl.c | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) (limited to 'usr.bin/perl') diff --git a/usr.bin/perl/Makefile b/usr.bin/perl/Makefile index 0eaf69c..17994de 100644 --- a/usr.bin/perl/Makefile +++ b/usr.bin/perl/Makefile @@ -2,7 +2,7 @@ PROG= perl NOMAN= -WARNS?= 6 +WARNS?= 5 LINKS= ${BINDIR}/perl ${BINDIR}/perl5 \ ${BINDIR}/perl ${BINDIR}/perl5.6.1 \ ${BINDIR}/perl ${BINDIR}/suidperl diff --git a/usr.bin/perl/perl.c b/usr.bin/perl/perl.c index cb43457..2bd55e7 100644 --- a/usr.bin/perl/perl.c +++ b/usr.bin/perl/perl.c @@ -30,6 +30,7 @@ __FBSDID("$FreeBSD$"); #include +#include #include #include @@ -49,8 +50,13 @@ main(int argc __unused, char *argv[]) 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 @@ -79,6 +85,10 @@ main(int argc __unused, char *argv[]) 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) err(1, "%s", path); -- cgit v1.1