Bug #78066 [Opn->Csd]: PHP eats the first byte of a program that comes from process substitution

From: Date: Mon, 15 Jul 2019 14:30:28 +0000
Subject: Bug #78066 [Opn->Csd]: PHP eats the first byte of a program that comes from process substitution
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-221788@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=78066&edit=1 ID: 78066 Updated by: nikic@php.net Reported by: octalbugsphp at alvarezp dot org Summary: PHP eats the first byte of a program that comes from process substitution -Status: Open +Status: Closed Type: Bug Package: *General Issues Operating System: Linux PHP Version: 7.3.5 -Assigned To: +Assigned To: nikic Block user comment: N Private report: N New Comment: Fixed by https://github.com/php/php-src/commit/c5f1b384b591009310370f0b06b10868d2d62741 for 7.4. Previous Comments: ------------------------------------------------------------------------ [2019-05-25 20:40:23] octalbugsphp at alvarezp dot org It should break all instances where the script file is a fifo. Blame shows commit 71ea95354b [1]: MFH: Corrected fix for bug #46844 to only trigger on the 1st line of CLI opened files. Which in turn references bug #46844: First line of included files not output if they begin with # [1] https://github.com/php/php-src/commit/71ea95354b4133f12dcf8207bc7b36e1562bdd65 [2] https://bugs.php.net/bug.php?id=46844 ------------------------------------------------------------------------ [2019-05-25 20:31:08] nikic@php.net We should probably move handling of shebang lines into the lexer. ------------------------------------------------------------------------ [2019-05-25 20:23:26] xatenev@php.net As pipes are simply not seekable a possible fix could be implemented by checking errno for ESPIPE as described here http://man7.org/linux/man-pages/man3/errno.3.html and either let it fail or do some /tmp redirect magic. ------------------------------------------------------------------------ [2019-05-25 20:07:32] xatenev@php.net ... Call the above snippet as specified in the bug report: gcc test.c ./a.out <(echo '<?php print("hello"); ?>') ----------------------------- Output: ?php print("hello"); ?> ------------------------------------------------------------------------ [2019-05-25 20:03:45] xatenev@php.net Hi, I was able to reproduce the problem with a small test C snippet that mimics what php-src is doing: ------------------------------------- #include <stdio.h> #include <stdlib.h> int main(int argc, char* argv[]) { FILE *fp; fp = fopen(argv[1], "rb"); char a = fgetc(fp); rewind(fp); char ch; while(1) { ch = fgetc(fp); if(feof(fp)) { break; } printf("%c", ch); } return 0; } ------------------------------------- rewind() fills errno with the value 29 which means Illegal seek. The lines char a = fgetc(fp); rewind(fp); mimic what php-src is doing here on line 606 and 620: https://github.com/php/php-src/blob/e6f86fb17cd3a2dfe94ca1a0113a23194cb1915a/sapi/cli/php_cli.c#L606-L620 It calls fgetc() to find out if shebang exists on the file pointer but rewind() doesn't work correctly. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=78066 -- Edit this bug report at https://bugs.php.net/bug.php?id=78066&edit=1

« previous php.bugs (#221788) next »