References: CVE-2026-16531
Description: libpcp_web: fix path traversal via hostname in the logger servlet
 pmLogGroupLabel() built paths from the hostname of a remote __pmLogLabel PDU.
 Taken from pcp 7.2.2, whose loggroup.c differs from 7.1.5 only in this fix.
 The openSUSE 6.3.8 backport omits it because that version has no logger servlet.

--- a/src/libpcp_web/src/loggroup.c
+++ b/src/libpcp_web/src/loggroup.c
@@ -581,6 +581,50 @@
     return count;
 }
 
+/*
+ * Check that a hostname string (which can arrive from a remote host),
+ * conforms to simple validity checks to ensure suspicious file system
+ * path names are not being injected.
+ */
+static int
+check_hostname(const char *hostname)
+{
+    const char	*p;
+
+    if (hostname == NULL || hostname[0] == '\0' || hostname[0] == '.')
+	return 0;
+    for (p = hostname; *p; p++) {
+	if (!isalnum((unsigned char)*p) &&
+	    *p != '-' && *p != '.' && *p != '_')
+	    return 0;
+    }
+    return 1;
+}
+
+/*
+ * Check that timezone/zoneinfo strings (similarly can arrive from a
+ * remote host), conform to simple validity checks; for timezone the
+ * string will be placed into the environment (TZ), but for zoneinfo
+ * file system path lookup will occur when accessing Olsen database.
+ */
+static int
+check_tz(const char *tz)
+{
+    const char	*p;
+
+    if (tz == NULL || tz[0] == '\0')
+	return 1;	/* empty/NULL timezone is valid (use system default) */
+    if (tz[0] == '/')
+	return 0;
+    for (p = tz; *p; p++) {
+	if (!isalnum((unsigned char)*p) && strchr("/_+-.:,", *p) == NULL)
+	    return 0;
+    }
+    if (strstr(tz, "..") != NULL)
+	return 0;
+    return 1;
+}
+
 int
 pmLogGroupLabel(pmLogGroupSettings *sp, const char *content, size_t length,
 		dict *params, void *arg)
@@ -610,6 +654,25 @@
     if (pmDebugOptions.log)
 	fprintf(stderr, "New archive label for host: %s\n", loglabel.hostname);
 
+    if (!check_hostname(loglabel.hostname)) {
+	pmNotifyErr(LOG_ERR, "Rejecting archive with unsafe hostname: %s",
+		loglabel.hostname ? loglabel.hostname : "(null)");
+	sts = -EINVAL;
+	goto fail;
+    }
+    if (!check_tz(loglabel.timezone)) {
+	pmNotifyErr(LOG_ERR, "Rejecting archive with unsafe timezone: %s",
+		loglabel.timezone ? loglabel.timezone : "(null)");
+	sts = -EINVAL;
+	goto fail;
+    }
+    if (!check_tz(loglabel.zoneinfo)) {
+	pmNotifyErr(LOG_ERR, "Rejecting archive with unsafe zoneinfo: %s",
+		loglabel.zoneinfo ? loglabel.zoneinfo : "(null)");
+	sts = -EINVAL;
+	goto fail;
+    }
+
     start = (time_t)loglabel.start.sec;
     if (localtime_r(&start, &tm) == NULL ||
         strftime(timebuf, sizeof(timebuf), TIME_FORMAT, &tm) < 2) {
