Skip to content

Commit 99313c1

Browse files
Add resolving of $PROGRAM_NAME from /dev/fd/<number>
There are situations when $PROGRAM_NAME is something /dev/fd/<number> 1) example like sudo /usr/local/bin/<tool> with checksum verification (GH#23351) 2) example with pipe: perl <( echo '#!perl -DA'; echo 'print "$0\n"');
1 parent 6fbe2c7 commit 99313c1

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,7 @@ Michael Somos <somos@grail.cba.csuohio.edu>
988988
Michael Stevens <mstevens@etla.org>
989989
Michael van Elst <mlelstv@serpens.de>
990990
Michael Witten <mfwitten@gmail.com>
991+
Michal Josef Špaček <mspacek@redhat.com>
991992
Michele Sardo
992993
Michiel Beijen <mb@x14.nl>
993994
Mik Firestone <fireston@lexmark.com>

perl.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4226,6 +4226,18 @@ S_open_script(pTHX_ const char *scriptname, bool dosearch, bool *suidscript)
42264226
scriptname = savepv(s + 1);
42274227
Safefree(PL_origfilename);
42284228
PL_origfilename = (char *)scriptname;
4229+
} else {
4230+
char proc_fd_path[64];
4231+
snprintf(proc_fd_path, sizeof(proc_fd_path), "/proc/self/fd/%d", fdscript);
4232+
char target_path[PATH_MAX];
4233+
ssize_t len = readlink(proc_fd_path, target_path, sizeof(target_path) - 1);
4234+
if (len != -1) {
4235+
Stat_t statbuf;
4236+
target_path[len] = '\0';
4237+
if (PerlLIO_stat(target_path, &statbuf) == 0 && S_ISREG(statbuf.st_mode)) {
4238+
scriptname = PL_origfilename = find_script(target_path, dosearch, NULL, 1);
4239+
}
4240+
}
42294241
}
42304242
}
42314243
}

0 commit comments

Comments
 (0)