Skip to content

Commit 6241f02

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 6241f02

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,7 @@ Michael Somos <[email protected]>
988988
Michael Stevens <[email protected]>
989989
Michael van Elst <[email protected]>
990990
Michael Witten <[email protected]>
991+
Michal Josef Špaček <[email protected]>
991992
Michele Sardo
992993
Michiel Beijen <[email protected]>
993994
Mik Firestone <[email protected]>

perl.c

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

0 commit comments

Comments
 (0)