Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FCGI_SOCKET_PERM environment variable does not work properly #22

Open
zhangyoufu opened this issue Dec 9, 2022 · 3 comments
Open

FCGI_SOCKET_PERM environment variable does not work properly #22

zhangyoufu opened this issue Dec 9, 2022 · 3 comments
Assignees

Comments

@zhangyoufu
Copy link

cgi-fast/lib/CGI/Fast.pm

Lines 50 to 57 in 280de79

if ($ENV{FCGI_SOCKET_PATH} or $socket) {
my $path = $ENV{FCGI_SOCKET_PATH} || $socket;
my $perm = $ENV{FCGI_SOCKET_PERM} || $socket_perm;
my $backlog = $ENV{FCGI_LISTEN_QUEUE} || $queue || 100;
my $socket = FCGI::OpenSocket( $path, $backlog );
if ($path !~ /^:/ && defined $perm) {
chmod $perm, $path or croak( "Couldn't chmod($path): $!" );
}

chmod LIST
Changes the permissions of a list of files. The first element of the list must be the numeric mode, which should probably be an octal number, and which definitely should not be a string of octal digits: 0644 is okay, but "0644" is not. Returns the number of files successfully changed. See also oct if all you have is a string.

@leejo
Copy link
Owner

leejo commented Dec 9, 2022

Hi.

Can you be more explicit about "does not work properly"? It seems when this was added test coverage was also added to exercise it: e9ba614#diff-57190e78b777d72bce3bdb69a08d4f9d60bfb22110c0cd0ac31cd931d2267358. I assume this is down to the ENV variable being stringified, tweaking the test coverage here to prove the bug would be a good first step.

Thanks.

@leejo leejo assigned leejo and zhangyoufu and unassigned leejo Dec 9, 2022
@zhangyoufu
Copy link
Author

Can you be more explicit about "does not work properly"?

The chmod perldoc describes exactly what I am facing.

my $mode = "0644"; chmod $mode, "foo"; # !!! sets mode to --w----r-T

We need to change $ENV{FCGI_SOCKET_PERM} to oct($ENV{FCGI_SOCKET_PERM}).

@leejo
Copy link
Owner

leejo commented Dec 9, 2022

Yes, that I understood. The problem here is backwards compatibility. If the FCGI_SOCKET_PERM environment variable has been passed in from the shell it will indeed be stringified, however if it is set as part of the process that then calls this (like the test) it could be octal already. Witness:

[leejohnson@lee-nuc J0 C1027 11:32:45 ]
/tmp > ls -l foo bar baz
-rw-rw-rw- 1 leejohnson 0 Dec  9 11:32 bar
-rw-rw-rw- 1 leejohnson 0 Dec  9 11:32 baz
-rw-rw-rw- 1 leejohnson 0 Dec  9 11:32 foo

[leejohnson@lee-nuc J0 C1028 11:32:50 ]
/tmp > perl -E'$ENV{FCGI_SOCKET_PERM}=0644; chmod( $ENV{FCGI_SOCKET_PERM},"foo" ); chmod( oct( $ENV{FCGI_SOCKET_PERM} ),"bar" );'

[leejohnson@lee-nuc J0 C1029 11:33:09 ]
/tmp > ls -l foo bar baz
-r---w---- 1 leejohnson 0 Dec  9 11:32 bar
-rw-rw-rw- 1 leejohnson 0 Dec  9 11:32 baz
-rw-r--r-- 1 leejohnson 0 Dec  9 11:32 foo

We don't get the correct perms on bar as we called oct on something that didn't need it, that's a regression. So we need to call oct on the ENV variable but only if it is stringified and not already octal...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants