Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

httpd_req_get_hdr_value_str() fails to find a field key after an empty value (IDFGH-1539) #3803

Closed
yappy opened this issue Jul 20, 2019 · 3 comments
Assignees

Comments

@yappy
Copy link

yappy commented Jul 20, 2019

Environment

  • IDF version (run git describe --tags to find it):
    v3.2
  • Build System: Make
  • Compiler version (run xtensa-esp32-elf-gcc --version to find it):
    1.22.0-80-g6c4433a
  • Operating System: Windows (WSL)
  • Power Supply: USB

Problem Description

When there is an empty value entry in HTTP header, httpd_req_get_hdr_value_str() returns ESP_ERR_NOT_FOUND.

Content-Type:<space><cr><lf>
X-FILE-NAME:<space>index.lua<cr><lf>

CANNOT find X-FILE-NAME
If Content-Type is not empty (e.g. image/jpeg) , it succeeds.

Expected Behavior

httpd_req_get_hdr_value_str() succeeds and returns its value. (index.lua)

Actual Behavior

httpd_req_get_hdr_value_str() returns ESP_ERR_NOT_FOUND.

Steps to repropduce

image

Code to reproduce this issue

const uint32_t HTTP_FILE_NAME_MAX = 32;
char name[HTTP_FILE_NAME_MAX];
ret = httpd_req_get_hdr_value_str(req, "X-FILE-NAME", name, sizeof(name));
@github-actions github-actions bot changed the title httpd_req_get_hdr_value_str() fails to find a field key after an empty value httpd_req_get_hdr_value_str() fails to find a field key after an empty value (IDFGH-1539) Jul 20, 2019
@anurag-kar
Copy link
Contributor

anurag-kar commented Jul 21, 2019

@yappy Thanks for reporting the issue. This patch should fix it. Let me know if it works for you. In the meanwhile we'll try to merge the bugfix as soon as possible.

@yappy
Copy link
Author

yappy commented Jul 22, 2019

Thank you very much!
It works in my app. It is not urgent for me because there is a workaround (set a non-empty value on the client side) for it.

yappy added a commit to yappy/DollsWatch that referenced this issue Jul 22, 2019
@yappy
Copy link
Author

yappy commented Sep 10, 2019

Any update on this?

@igrr igrr closed this as completed in a6cc964 Sep 12, 2019
igrr pushed a commit that referenced this issue Sep 16, 2019
This MR is intended to fix incorrect parsing of HTTP requests when empty header values are present.

The issue is was due to asymmetric behavior of `http_parser` library, which in case of:
* non-empty header values : invokes callbacks with the pointer to the start of a value
* empty header values : invokes callbacks with pointer to the start of next header or section

Since HTTP server relies on this pointer (along with length of the value) to locate the end of a value, and replace the line terminators (CRLFs) with null characters, the second case needed to be handled correctly.

Closes IDFGH-1539

Closes #3803

Backports !5663
igrr pushed a commit that referenced this issue Sep 16, 2019
This MR is intended to fix incorrect parsing of HTTP requests when empty header values are present.

The issue is was due to asymmetric behavior of `http_parser` library, which in case of:

    non-empty header values : invokes callbacks with the pointer to the start of a value
    empty header values : invokes callbacks with pointer to the start of next header or section

Since HTTP server relies on this pointer (along with length of the value) to locate the end of a value, and replace the line terminators (CRLFs) with null characters, the second case needed to be handled correctly.

Closes IDFGH-1539

Closes #3803
igrr pushed a commit that referenced this issue Sep 21, 2019
This MR is intended to fix incorrect parsing of HTTP requests when empty header values are present.

The issue is was due to asymmetric behavior of `http_parser` library, which in case of:

    non-empty header values : invokes callbacks with the pointer to the start of a value
    empty header values : invokes callbacks with pointer to the start of next header or section

Since HTTP server relies on this pointer (along with length of the value) to locate the end of a value, and replace the line terminators (CRLFs) with null characters, the second case needed to be handled correctly.

Closes IDFGH-1539

Closes #3803
loganfin pushed a commit to Lumenaries/esp_http_server that referenced this issue Apr 23, 2024
This MR is intended to fix incorrect parsing of HTTP requests when empty header values are present.

The issue is was due to asymmetric behavior of `http_parser` library, which in case of:

    non-empty header values : invokes callbacks with the pointer to the start of a value
    empty header values : invokes callbacks with pointer to the start of next header or section

Since HTTP server relies on this pointer (along with length of the value) to locate the end of a value, and replace the line terminators (CRLFs) with null characters, the second case needed to be handled correctly.

Closes IDFGH-1539

Closes espressif/esp-idf#3803
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants