From 41d309d438800102fc8aed736642e22da9f599fc Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Mon, 1 Sep 2025 11:22:58 +0200 Subject: check_snmp: improve string quoting in result --- plugins/check_snmp.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c index d5abd8c2..3c054259 100644 --- a/plugins/check_snmp.c +++ b/plugins/check_snmp.c @@ -235,8 +235,23 @@ int main(int argc, char **argv) { if (verbose) { printf("Debug: Got a string\n"); } + char *tmp = (char *)vars->val.string; - xasprintf(&sc_oid_test.output, "%s - Value: %s", sc_oid_test.output, tmp); + + if (strchr(tmp, '"') != NULL) { + // got double quote in the string + if (strchr(tmp, '\'') != NULL) { + // got single quote in the string too + // dont quote that at all to avoid even more confusion + xasprintf(&sc_oid_test.output, "%s - Value: %s", sc_oid_test.output, tmp); + } else { + // quote with single quotes + xasprintf(&sc_oid_test.output, "%s - Value: '%s'", sc_oid_test.output, tmp); + } + } else { + // quote with double quotes + xasprintf(&sc_oid_test.output, "%s - Value: \"%s\"", sc_oid_test.output, tmp); + } if (strlen(tmp) == 0) { sc_oid_test = mp_set_subcheck_state(sc_oid_test, config.nulloid_result); -- cgit v1.2.3-74-g34f1