]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
hs: Double quote the metrics label value
authorDavid Goulet <dgoulet@torproject.org>
Wed, 2 Feb 2022 18:51:22 +0000 (13:51 -0500)
committerDavid Goulet <dgoulet@torproject.org>
Thu, 3 Feb 2022 13:30:23 +0000 (08:30 -0500)
Fixes #40552

Signed-off-by: David Goulet <dgoulet@torproject.org>
changes/ticket40552 [new file with mode: 0644]
src/feature/hs/hs_metrics.c
src/test/test_metrics.c

diff --git a/changes/ticket40552 b/changes/ticket40552
new file mode 100644 (file)
index 0000000..7811f3a
--- /dev/null
@@ -0,0 +1,3 @@
+  o Minor bugfixes (MetricsPort, Prometheus):
+    - Add double quotes to the label values of the onion service metrics. Fixes
+      bug 40552; bugfix on 0.4.5.1-alpha.
index e6d3084f2690ab471f4f0cf85fe9e76171f6ceb6..452bb44419b934094a1ca7116e01665461760300 100644 (file)
@@ -32,12 +32,16 @@ port_to_str(const uint16_t port)
 /** Return a static buffer pointer that contains a formatted label on the form
  * of key=value.
  *
+ * NOTE: Important, label values MUST NOT contain double quotes else, in the
+ * case of Prometheus, it will fail with a malformed line because we force the
+ * label value to be enclosed in double quotes.
+ *
  * Subsequent call to this function invalidates the previous buffer. */
 static const char *
 format_label(const char *key, const char *value)
 {
   static char buf[128];
-  tor_snprintf(buf, sizeof(buf), "%s=%s", key, value);
+  tor_snprintf(buf, sizeof(buf), "%s=\"%s\"", key, value);
   return buf;
 }
 
index 152dd99d235de6065e3758acc23de0f095f8f855..58628e8483dbdd3c2ee6869c85d19f583d8c114f 100644 (file)
@@ -30,8 +30,8 @@
 
 #define TEST_METRICS_ENTRY_NAME    "entryA"
 #define TEST_METRICS_ENTRY_HELP    "Description of entryA"
-#define TEST_METRICS_ENTRY_LABEL_1 "label=farfadet"
-#define TEST_METRICS_ENTRY_LABEL_2 "label=ponki"
+#define TEST_METRICS_ENTRY_LABEL_1 "label=\"farfadet\""
+#define TEST_METRICS_ENTRY_LABEL_2 "label=\"ponki\""
 
 static void
 set_metrics_port(or_options_t *options)