jpbarrette/curlpp

crash when getting ContentType if server does not set it

arolson101 opened this issue · 3 comments

If the server doesn't send a content-type header, and you do:

auto contentType = curlpp::infos::ContentType::get(request);

it will crash here:

template<>
void
InfoTypeConverter<std::string>::get(const curlpp::Easy & handle, 
				      CURLINFO info,
				      std::string & value)
{
  char * tmp;
  InfoGetter::get(handle, info, tmp);
  value = tmp; // CRASH
}

because tmp will be null. This is a valid condition according to the documentation:
https://curl.haxx.se/libcurl/c/CURLINFO_CONTENT_TYPE.html

I think returning empty value when content-type is invalid or empty shold be acceptable.

Can you try to replace the code by this, and let me know if it works ?

template<>
void
InfoTypeConverter<std::string>::get(const curlpp::Easy & handle, 
				      CURLINFO info,
				      std::string & value)
{
  char * tmp = NULL;
  InfoGetter::get(handle, info, tmp);
  if (tmp == NULL)
    value.clear();
  else
    value = tmp;
}

that works

Thanks,
Fix is pushed into develop branch (5428ee1).