cpp-netlib/uri

network::uri_builder::uri() method crashes with special user_info string

Closed this issue · 9 comments

I tried setting the following as basically blank userid and password fields for the FTP credentials. The mlfBldr.uri() crashes with the expression string iterator + offset out of range.

    static const std::string gUserInfo(":");
    network::uri_builder mlfBldr;
    mlfBldr.scheme("ftp").host(nicHost).user_info(gUserInfo);
    auto uri = mlfBldr.uri();

The code breaks in the 3rd last line of the snuppet below from uri.cpp (from the uri subproject). I was expecting to either have an error indicating that the ":" paramter was illegal or am pretty sure that the problem is due to the while ((':' == *it) || ('/' == *it)) as the code there does not expect a : to follow (as is the case when the userid password are set to null. as per calling the method uri_builder::user_info(":") - this leaves the iterator pointing to the 3rd occurrence of a colon in this URI. Also if I change the userid/password to " :" leaving a single space in for the userid then things work fine.

auto it = std::begin(uri_);
if (scheme) {
  uri_parts_.scheme.reset(
      copy_range(std::begin(*scheme), std::end(*scheme), it));
  // ignore ://
  while ((':' == *it) || ('/' == *it)) {
    ++it;
  }
}

if (user_info) {
  uri_parts_.hier_part.user_info.reset(
      copy_range(std::begin(*user_info), std::end(*user_info), it));
  ++it;  // ignore @
}

if (host) {
  uri_parts_.hier_part.host.reset(
      copy_range(std::begin(*host), std::end(*host), it));
}

Any news on this bug? I can verify that this is still broken. I have an FTP server that accepts enter\enter as the default userid/psssword and as such the string ":" is what I need to set the user_info field to.

I'm not able to reproduce this, could you provide a minimal example that shows this error that I can run here?

Glynn, see my initial report, it still breaks there, I simplified it here.

network::uri_builder bldr;
bldr.scheme("ftp")
    .host("localhost")
    .user_info(":");
auto uri = bldr.uri();

Glynn, Any luck with a fix for this one?

I have a unit test in my local repo with exactly this excerpt in it, and I am unable to reproduce your error. I'll take another look when I get home this evening.

Thanks Glyn, it's not Urgent, just a nice to have. Btw I'm quite new to
this github thing, will this project be merged back into the main line net
lib?
John
On Mar 25, 2014 11:33 AM, "Glyn Matthews" notifications@github.com wrote:

I have a unit test in my local repo with exactly this excerpt in it, and I
am unable to reproduce your error. I'll take another look when I get home
this evening.

Reply to this email directly or view it on GitHubhttps://github.com//issues/48#issuecomment-38578948
.

The project will be merged back in to cpp-netlib as long as the code is merged into the uri repo and the submodule in cpp-netlib is updated. I can do this soon.

I have reproduced this bug. The empty_username test in uri_builder_test.cpp fails for me. I'm running Visual Studio 2013, using the nmake generator.

I have a patch and can submit a pull request soon.

Should this issue be closed?