From 9760e1e8fc911410475cfc542be74bcaeb3248fe Mon Sep 17 00:00:00 2001 From: Amos Jeffries Date: Wed, 26 May 2010 15:43:53 +1200 Subject: [PATCH] Author: Alex Rousskov Bug 2633: Fix Ecap::HeaderRep::value(name) fails when there is no named header field Calling Adaptation::Ecap::HeaderRep::value(const Name &name) with names of header fields that do not exist leads to ICAP/AsyncJob.cc(218) dial: AsyncJob::noteStart threw exception: basic_string::_S_construct NULL not valid I suspect this is a combination of - std::string constructor incapable of handling a nil char* pointer. - String::termedBuf() returning an nil pointer when the string is empty. When there is no specified header field in the message, the value() wrapper in Squid gets an empty String for the header value, which is then used to create std::string, which fails or leads to failure. I think it is wrong for termedBuf to return nil (because nil is not 0-terminated). I have not tried to fix that because we will have a new String class soon. --- src/adaptation/ecap/MessageRep.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/adaptation/ecap/MessageRep.cc b/src/adaptation/ecap/MessageRep.cc index ac50b731ee..06e6cd34c8 100644 --- a/src/adaptation/ecap/MessageRep.cc +++ b/src/adaptation/ecap/MessageRep.cc @@ -38,7 +38,8 @@ Adaptation::Ecap::HeaderRep::value(const Name &name) const const String value = squidId == HDR_OTHER ? theHeader.getByName(name.image().c_str()) : theHeader.getStrOrList(squidId); - return Value::FromTempString(value.termedBuf()); + return value.defined() ? + Value::FromTempString(value.termedBuf()) : Value(); } void -- 2.47.3