Skip to content

Commit 95c644c

Browse files
author
Yieen
committed
test utils
1 parent 27a5978 commit 95c644c

File tree

3 files changed

+46
-7
lines changed

3 files changed

+46
-7
lines changed

cgi/bad_alloc.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// before main
2+
3+
bool randAllocFail;
4+
5+
void *operator new(size_t size) throw(std::bad_alloc) {
6+
if (randAllocFail && rand() % 100 == 0) {
7+
std::cerr << BRIGHT_YELLOW << "malloc(): ENOMEM" << RESET << std::endl;
8+
throw std::bad_alloc();
9+
}
10+
void *p = malloc(size);
11+
if (!p) throw std::bad_alloc();
12+
return p;
13+
};
14+
15+
void operator delete(void *p) throw() { free(p); }
16+
17+
void handler(int) {
18+
randAllocFail = !randAllocFail;
19+
std::cerr << "throw std::bad_alloc() randomdly: " << randAllocFail
20+
<< std::endl;
21+
}
22+
23+
// beginning of main
24+
{
25+
randAllocFail = false;
26+
unsigned int seed = 1697821214;
27+
std::ofstream debug("seed.txt");
28+
debug << "seed: " << seed << std::endl;
29+
srand(seed);
30+
signal(SIGQUIT, handler);
31+
}
32+
33+
// position where it should start to fail
34+
randAllocFail = true

cgi/cgi.conf

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
http {
22
include ../conf/mime.types;
3+
error_log cgi/error.log;
4+
access_log cgi/access.log;
35

46
server {
5-
listen 8080;
6-
root cgi;
7+
listen [::1]:8080;
8+
root wordpress;
79
index index.php;
810
allow GET POST PUT;
911
cgi php /usr/bin/php-cgi;

cgi/client.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,19 @@ int main(int, char **, char **) {
2727
}
2828
std::cout << "connected to: 127.0.0.1:8080" << std::endl;
2929
std::string msg;
30-
msg += "PUT /tmp.file HTTP/1.1\r\n";
30+
msg += "POST /dump.php HTTP/1.1\r\n";
3131
msg += "Host: 127.0.0.1\r\n";
3232
msg += "Transfer-Encoding: chunked\r\n";
33+
msg += "Content-Type: application/x-www-form-urlencoded\r\n";
3334
msg += "\r\n";
3435

3536
std::vector<std::string> body;
36-
body.push_back("hello world\r\n");
37-
body.push_back("\r\n");
38-
body.push_back("does it\r\n");
39-
body.push_back("work ???????????????????????????????????");
37+
body.push_back("hello=world");
38+
body.push_back("&bla=blup");
39+
body.push_back("&newline=some text with a newline\r\nin the middle");
40+
// body.push_back("does it\r\n");
41+
// body.push_back("work ???????????????????????????????????");
42+
4043
write(fd, msg.c_str(), msg.size());
4144

4245
for (size_t i = 0; i < body.size(); ++i) {

0 commit comments

Comments
 (0)