serrislew commented on code in PR #13475:
URL: https://github.com/apache/trafficserver/pull/13475#discussion_r3715579903
##########
plugins/slice/client.cc:
##########
@@ -19,9 +19,46 @@
#include "client.h"
#include "Config.h"
+#include "server.h"
#include "util.h"
+#include "swoc/TextView.h"
+
+#include <cctype>
#include <cinttypes>
+#include <limits>
+
+namespace
+{
+// Miss bound for this purge: the request header when usable, else the config
value.
+int
+purge_miss_bound(HttpHeader const &header, Config const *const conf)
+{
+ char probestr[64];
+ int probelen = sizeof(probestr);
+
+ if (!header.valueForKey(conf->m_purge_probe_header.data(),
conf->m_purge_probe_header.size(), probestr, &probelen)) {
+ return conf->m_purge_probe_blocks;
+ }
+
+ swoc::TextView value{probestr, static_cast<size_t>(probelen)};
+ // isspace is only defined for values representable as unsigned char
+ value.trim_if([](char c) { return 0 != isspace(static_cast<unsigned
char>(c)); });
+
+ swoc::TextView parsed;
+ intmax_t const blocks = swoc::svtoi(value, &parsed, 10);
+
+ // parsed must cover the whole value: "8abc" is a mistake, not eight blocks
+ if (parsed.size() != value.size() || blocks <= 0 ||
std::numeric_limits<int>::max() < blocks) {
+ ERROR_LOG("Ignoring invalid %.*s value '%.*s'",
static_cast<int>(conf->m_purge_probe_header.size()),
Review Comment:
Should this use `canLogError()`? Can this spam our error logs?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]