Skip to main content
added 111 characters in body
Source Link
Yuri Laguardia
  • 2.6k
  • 1
  • 10
  • 17

The strtok() call here:

char* absolute_path = strtok(req_tar, "?");

will crop req_tar at the ? and make it always be equal to abs_path.

Because of this, the following condition will never be true and you'll never extract query:

if(strcmp(req_tar, abs_path) != 0)
    query = strstr(req_tar, abs_path);

But even if that condition triggered, I don't think you understand what query should be.

Given a line "GET /hello.php?name=Alice HTTP/1.1\r\n", this is what you should extract:

  • abs_path should be /hello.php
  • query should be name=Alice

And this query = strstr(req_tar, abs_path); wouldn't make query become this name=Alice.

Here you can see the first part of your approach in action and what it does to req_tar: https://goo.gl/OzkIXX (wait some seconds for the code to load and then use the forward button to step through your code)

The strtok() call here:

char* absolute_path = strtok(req_tar, "?");

will crop req_tar at the ? and make it always be equal to abs_path.

Because of this, the following condition will never be true and you'll never extract query:

if(strcmp(req_tar, abs_path) != 0)
    query = strstr(req_tar, abs_path);

But even if that condition triggered, I don't think you understand what query should be.

Given a line "GET /hello.php?name=Alice HTTP/1.1\r\n", this is what you should extract:

  • abs_path should be /hello.php
  • query should be name=Alice

And this query = strstr(req_tar, abs_path); wouldn't make query become this name=Alice.

The strtok() call here:

char* absolute_path = strtok(req_tar, "?");

will crop req_tar at the ? and make it always be equal to abs_path.

Because of this, the following condition will never be true and you'll never extract query:

if(strcmp(req_tar, abs_path) != 0)
    query = strstr(req_tar, abs_path);

But even if that condition triggered, I don't think you understand what query should be.

Given a line "GET /hello.php?name=Alice HTTP/1.1\r\n", this is what you should extract:

  • abs_path should be /hello.php
  • query should be name=Alice

And this query = strstr(req_tar, abs_path); wouldn't make query become this name=Alice.

Here you can see the first part of your approach in action and what it does to req_tar: https://goo.gl/OzkIXX (wait some seconds for the code to load and then use the forward button to step through your code)

Source Link
Yuri Laguardia
  • 2.6k
  • 1
  • 10
  • 17

The strtok() call here:

char* absolute_path = strtok(req_tar, "?");

will crop req_tar at the ? and make it always be equal to abs_path.

Because of this, the following condition will never be true and you'll never extract query:

if(strcmp(req_tar, abs_path) != 0)
    query = strstr(req_tar, abs_path);

But even if that condition triggered, I don't think you understand what query should be.

Given a line "GET /hello.php?name=Alice HTTP/1.1\r\n", this is what you should extract:

  • abs_path should be /hello.php
  • query should be name=Alice

And this query = strstr(req_tar, abs_path); wouldn't make query become this name=Alice.