From: Michael Tremer Date: Fri, 28 Nov 2025 16:01:27 +0000 (+0000) Subject: source: Enforce rrdtool's limits on field names X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9cdef61714b4a00cac1c89430a93c3d0ecb3e778;p=telemetry.git source: Enforce rrdtool's limits on field names Fields in RRD files can only be up to 19 characters long and may only contain A-Za-z0-9\-_. Signed-off-by: Michael Tremer --- diff --git a/src/daemon/source.c b/src/daemon/source.c index 74c9609..d1f645e 100644 --- a/src/daemon/source.c +++ b/src/daemon/source.c @@ -394,6 +394,50 @@ static int td_source_init(td_source* self) { return r; } +static int td_source_check_data_sources(td_source* self) { + for (const td_rrd_ds* ds = self->impl->rrd_dss; ds->field; ds++) { + // Check if the field name is empty + if (!ds->field || !*ds->field) { + ERROR(self->ctx, "Empty DS field in %s\n", td_source_name(self)); + return -EINVAL; + } + + // Check field name length + size_t length = strlen(ds->field); + + // Fail if it is too long + if (length > 19) { + ERROR(self->ctx, "DS field name is too long: %s. " + "Must be <= 19 characters, but is %ld.\n", ds->field, length); + return -EINVAL; + } + + // Check for invalid characters + for (const char* p = ds->field; *p; p++) { + // A-Z/a-z are allowed + if (isalpha(*p)) + continue; + + // Digits are allowed + if (isdigit(*p)) + continue; + + // Special characters + switch (*p) { + case '-': + case '_': + continue; + + default: + ERROR(self->ctx, "DS field name contains invalid characters: %s\n", ds->field); + return -EINVAL; + } + } + } + + return 0; +} + static int td_source_check(td_source* self) { // Check if name is set if (!self->impl->name) { @@ -408,7 +452,8 @@ static int td_source_check(td_source* self) { return -EINVAL; } - return 0; + // Check data sources + return td_source_check_data_sources(self); } static void td_source_free(td_source* self) {