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

Possible bug: header name doesn't get regex-matched in non-strict mode if the corresponding value is empty #51

Closed
tsilia opened this issue Dec 23, 2020 · 0 comments · Fixed by #52

Comments

@tsilia
Copy link
Contributor

tsilia commented Dec 23, 2020

Hello.
In the mime.cpp there could be a logic error introduced along with adding support for non-strict mode. As you can see in the source file:

mailio/src/mime.cpp

Lines 703 to 711 in 3fccce6

if (header_value.empty())
if (_strict_mode)
throw mime_error("Parsing failure, header name or value empty: " + header_line);
else
return;
smatch m;
if (!regex_match(header_name, m, HEADER_NAME_REGEX))
throw mime_error("Format failure of the header name `" + header_name + "`.");

in case when the method accepts an empty header_value, header_name wouldn't get checked with regex_match because the code would have returned before this check. But it seems reasonable to check the header_name regardless of whether the mode is strict or not.

I've checked this using the following code and the behaviour was different in two cases: empty value and non-empty value. In the second case an exception is thrown:

msg_wrapper msg;
msg.strict_mode(false);
msg.strict_codec_mode(false);
std::string header_name, header_value;
msg.ParseHeader("Invalid header: ", header_name, header_value);
msg.ParseHeader("Invalid header: non-empty value", header_name, header_value); // exception

(msg_wrapper is a thin wrapper class as mime::parse_header_name_value() method is protected).

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 a pull request may close this issue.

1 participant