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

Fix the va_args order of http header #286

Merged

Conversation

beef9999
Copy link
Collaborator

@beef9999 beef9999 commented Dec 3, 2023

The current HTTP header has a bug of wrong key value order.
This is the POC. It will print v first, and then k, which is obviously wrong.

#include <iostream>
#include <string>
#include <map>
#include <string>
#include <cstdarg>

std::map<std::string, std::string> common_header;

void add_header(va_list args) {
    common_header[va_arg(args, const char*)] = va_arg(args, const char*);
}

void f(int a, ...) {
    va_list args;
    va_start(args, a);
    add_header(args);
    va_end(args);
}

int main() {
    f(1, "k", "v");
    for (auto& i: common_header) {
        std::cout << i.first << std::endl;
        std::cout << i.second << std::endl;
    }
}

@lihuiba lihuiba merged commit b22dcec into alibaba:main Dec 4, 2023
7 checks passed
beef9999 added a commit that referenced this pull request Dec 4, 2023
@beef9999 beef9999 deleted the beef9999/fix-va_args-order-of-http-header branch December 21, 2023 16:07
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

Successfully merging this pull request may close these issues.

2 participants