Skip to content

Commit

Permalink
Merge pull request #7 from david-caro/main
Browse files Browse the repository at this point in the history
cite2template: Read only $CONTENT_LENGTH bytes from POST requests
  • Loading branch information
Saisengen committed Mar 14, 2024
2 parents f1cd5a9 + ffb2d05 commit d929af1
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion web-services/cite2template/cite2template.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,24 @@ static void Main()
bool addauthor = false;
bool method_is_post = Environment.GetEnvironmentVariable("REQUEST_METHOD") == "POST";
if (!method_is_post)
{
Sendresponse("", false, "", "");
}
else
{
var inputdata = Console.ReadLine().Split('&');
string[] inputdata;
// The CGI 1.1 standard does not specify that the input will be terminated with EOF
// So if there's content length, we have to read just as many chars
var inputLength = int.Parse(Environment.GetEnvironmentVariable("CONTENT_LENGTH")!);
var inputstring = "";
for (int i = 0; i < inputLength; i++){
var nextChar = Console.Read();
if (nextChar == -1) {
break;
}
inputstring += (char)nextChar;
}
inputdata = inputstring.Split('&');
foreach (var param in inputdata)
{
var data = param.Split('=');
Expand Down

0 comments on commit d929af1

Please sign in to comment.