Skip to content

Commit

Permalink
Maintenance: use SBufs for ErrorDetailEntry data fields (#1451)
Browse files Browse the repository at this point in the history
Also fixed (re)configuration crashes when an error-details.txt entry is
missing a required "detail" or "descr" field.
  • Loading branch information
kinkie authored and squid-anubis committed Oct 4, 2023
1 parent 608c50d commit 133ade7
Show file tree
Hide file tree
Showing 10 changed files with 245 additions and 185 deletions.
20 changes: 20 additions & 0 deletions src/HttpHeader.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,26 @@ class HttpHeader

int httpHeaderParseQuotedString(const char *start, const int len, String *val);

namespace Http {

/**
* Parses an HTTP quoted-string sequence (RFC 9110, Section 5.6.4).
*
* \param a brief human-friendly description of the string being parsed
* \param start input buffer (an opening double-quote is expected at *start)
* \param length is the number of characters in the given buffer
*
* \returns string contents with open/closing quotes stripped and any quoted-pairs decoded
*
* Avoid this slow function on performance-sensitive code paths.
* TODO: Replace with an efficient, SBuf-friendly implementation.
*
* \sa httpHeaderParseQuotedString() for a String-friendly function.
*/
SBuf SlowlyParseQuotedString(const char *description, const char *start, size_t length);

}

/// quotes string using RFC 7230 quoted-string rules
SBuf httpHeaderQuoteString(const char *raw);

Expand Down
11 changes: 11 additions & 0 deletions src/HttpHeaderTools.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include "HttpHeaderTools.h"
#include "HttpRequest.h"
#include "MemBuf.h"
#include "sbuf/Stream.h"
#include "sbuf/StringConvert.h"
#include "SquidConfig.h"
#include "Store.h"
#include "StrList.h"
Expand Down Expand Up @@ -233,6 +235,15 @@ httpHeaderParseQuotedString(const char *start, const int len, String *val)
return 1;
}

SBuf
Http::SlowlyParseQuotedString(const char * const description, const char * const start, const size_t length)
{
String s;
if (!httpHeaderParseQuotedString(start, length, &s))
throw TextException(ToSBuf("Cannot parse ", description, " as a quoted string"), Here());
return StringToSBuf(s);
}

SBuf
httpHeaderQuoteString(const char *raw)
{
Expand Down
Loading

0 comments on commit 133ade7

Please sign in to comment.