diff --git a/cgi-bin/uploads/en.subject.pdf b/cgi-bin/uploads/en.subject.pdf new file mode 100644 index 0000000..aa6f72d Binary files /dev/null and b/cgi-bin/uploads/en.subject.pdf differ diff --git a/conf/default.conf b/conf/default.conf index e1a3c0e..bc31e28 100644 --- a/conf/default.conf +++ b/conf/default.conf @@ -3,7 +3,7 @@ server { server_name localhost; root ./; autoindex on; - client_max_body_size 10m; + client_max_body_size 1m; index assets/index.html; use_chunked_encoding true; chunk_size 100; diff --git a/src/Cgi/Cgi.cpp b/src/Cgi/Cgi.cpp index c75708d..b4b61b2 100644 --- a/src/Cgi/Cgi.cpp +++ b/src/Cgi/Cgi.cpp @@ -420,10 +420,17 @@ int handleCgi( HttpRequest& req ){ int inputPipe[2], outputPipe[2]; pid_t pid; + size_t maxBodySize = req.getServer().getBodySize();//later add here location conf maxbody size + //clean body first if (req.getMethod() == "POST") { // Create a local copy of the body first std::string body = req.getBody(); + //std::cout << "body size " << body.size() << "max body size " << maxBodySize << "\n"; + if(body.size() > maxBodySize ){ + std::cerr << RED << "ERROR: Cgi: POST TO BIG" << END << std::endl; + return (-1);//mabe add a error page here + } while (!body.empty() && (body[body.size()-1] == '\n' || body[body.size()-1] == '\r')) { body.erase(body.size() -1 ); }