mirror of
https://github.com/lammertb/libhttp.git
synced 2026-01-03 16:02:30 +03:00
On windows, enclosing path to CGI script in quotes to allow paths with spaces
This commit is contained in:
@@ -1341,7 +1341,7 @@ static pid_t spawn_process(struct mg_connection *conn, const char *prog,
|
||||
}
|
||||
GetFullPathNameA(dir, sizeof(full_dir), full_dir, NULL);
|
||||
|
||||
mg_snprintf(conn, cmdline, sizeof(cmdline), "%s%s%s\\%s",
|
||||
mg_snprintf(conn, cmdline, sizeof(cmdline), "%s%s\"%s\\%s\"",
|
||||
interp, interp[0] == '\0' ? "" : " ", full_dir, prog);
|
||||
|
||||
DEBUG_TRACE(("Running [%s]", cmdline));
|
||||
|
||||
3
test/dir with spaces/hello.cgi
Executable file
3
test/dir with spaces/hello.cgi
Executable file
@@ -0,0 +1,3 @@
|
||||
#!/usr/bin/env perl
|
||||
|
||||
print "Content-Type: text/plain\n\nhello\n";
|
||||
24
test/test.pl
24
test/test.pl
@@ -19,9 +19,10 @@ my $test_dir_uri = "test_dir";
|
||||
my $root = 'test';
|
||||
my $test_dir = $root . $dir_separator. $test_dir_uri;
|
||||
my $config = 'mongoose.conf';
|
||||
my $exe = '.' . $dir_separator . 'mongoose';
|
||||
my $embed_exe = '.' . $dir_separator . 'embed';
|
||||
my $unit_test_exe = '.' . $dir_separator . 'unit_test';
|
||||
my $exe_ext = on_windows() ? '.exe' : '';
|
||||
my $mongoose_exe = '.' . $dir_separator . 'mongoose' . $exe_ext;
|
||||
my $embed_exe = '.' . $dir_separator . 'embed' . $exe_ext;
|
||||
my $unit_test_exe = '.' . $dir_separator . 'unit_test' . $exe_ext;
|
||||
my $exit_code = 0;
|
||||
|
||||
my @files_to_delete = ('debug.log', 'access.log', $config, "$root/a/put.txt",
|
||||
@@ -51,9 +52,9 @@ sub get_num_of_log_entries {
|
||||
# Send the request to the 127.0.0.1:$port and return the reply
|
||||
sub req {
|
||||
my ($request, $inc, $timeout) = @_;
|
||||
my $sock = IO::Socket::INET->new(Proto=>"tcp",
|
||||
PeerAddr=>'127.0.0.1', PeerPort=>$port);
|
||||
fail("Cannot connect: $!") unless $sock;
|
||||
my $sock = IO::Socket::INET->new(Proto => 6,
|
||||
PeerAddr => '127.0.0.1', PeerPort => $port);
|
||||
fail("Cannot connect to http://127.0.0.1:$port : $!") unless $sock;
|
||||
$sock->autoflush(1);
|
||||
foreach my $byte (split //, $request) {
|
||||
last unless print $sock $byte;
|
||||
@@ -97,7 +98,6 @@ sub spawn {
|
||||
if (on_windows()) {
|
||||
my @args = split /\s+/, $cmdline;
|
||||
my $executable = $args[0];
|
||||
$executable .= '.exe';
|
||||
Win32::Spawn($executable, $cmdline, $pid);
|
||||
die "Cannot spawn @_: $!" unless $pid;
|
||||
} else {
|
||||
@@ -155,13 +155,13 @@ if (scalar(@ARGV) > 0 and $ARGV[0] eq 'unit') {
|
||||
# Command line options override config files settings
|
||||
write_file($config, "access_log_file access.log\n" .
|
||||
"listening_ports 127.0.0.1:12345\n");
|
||||
spawn("$exe -listening_ports 127.0.0.1:$port");
|
||||
spawn("$mongoose_exe -listening_ports 127.0.0.1:$port");
|
||||
o("GET /test/hello.txt HTTP/1.0\n\n", 'HTTP/1.1 200 OK', 'Loading config file');
|
||||
unlink $config;
|
||||
kill_spawned_child();
|
||||
|
||||
# Spawn the server on port $port
|
||||
my $cmd = "$exe ".
|
||||
my $cmd = "$mongoose_exe ".
|
||||
"-listening_ports 127.0.0.1:$port ".
|
||||
"-access_log_file access.log ".
|
||||
"-error_log_file debug.log ".
|
||||
@@ -352,6 +352,8 @@ unless (scalar(@ARGV) > 0 and $ARGV[0] eq "basic_tests") {
|
||||
unlink "$root/.htpasswd";
|
||||
|
||||
|
||||
o("GET /dir%20with%20spaces/hello.cgi HTTP/1.0\n\r\n",
|
||||
'HTTP/1.1 200 OK.+hello', 'CGI script with spaces in path');
|
||||
o("GET /env.cgi HTTP/1.0\n\r\n", 'HTTP/1.1 200 OK', 'GET CGI file');
|
||||
o("GET /bad2.cgi HTTP/1.0\n\n", "HTTP/1.1 123 Please pass me to the client\r",
|
||||
'CGI Status code text');
|
||||
@@ -410,9 +412,9 @@ unless (scalar(@ARGV) > 0 and $ARGV[0] eq "basic_tests") {
|
||||
# Manipulate the passwords file
|
||||
my $path = 'test_htpasswd';
|
||||
unlink $path;
|
||||
system("$exe -A $path a b c") == 0
|
||||
system("$mongoose_exe -A $path a b c") == 0
|
||||
or fail("Cannot add user in a passwd file");
|
||||
system("$exe -A $path a b c2") == 0
|
||||
system("$mongoose_exe -A $path a b c2") == 0
|
||||
or fail("Cannot edit user in a passwd file");
|
||||
my $content = read_file($path);
|
||||
$content =~ /^b:a:\w+$/gs or fail("Bad content of the passwd file");
|
||||
|
||||
Reference in New Issue
Block a user