[PATCH bpf-next] selftests/bpf: Sanitize traffic monitor log file names

Vineet Gupta <[email protected]>
Newsgroups org.kernel.vger.bpf
Message-ID <[email protected]>
The traffic monitor names its capture logs after the test and subtest
being run, replacing '/' and ' ' so the result is usable as a file name.
Test names are free form though, and other characters make it through.
A subtest called "INET4: bpf timestamping" produces

  /tmp/tmon_pcap/packets-125-15-net_timestamping__INET4:_bpf_timestamping-net_timestamping_ns.log

CI systems that collect these logs as artifacts reject such names.
GitHub Actions' upload-artifact fails the upload with

  Error: The path for one of the files in artifact is not valid:
  ... Contains the following character:  Colon :

Replace the whole set of awkward characters in one pass rather than
adding another strchr() loop per character. Note the loop tests *p
before calling strchr(), so the terminating NUL is never passed to it.

This came up as a side error/annoyance when trying to re-enable BPF-GCC
CI runs [1]. The CI side already has path name normalization and needs
some tweaking as well, however fixing it at the source also makes sense.

Fixes: f52403b6bfea ("selftests/bpf: Add traffic monitor functions.")
Link: https://github.com/kernel-patches/vmtest/actions/runs/30710914503/job/91399011388 [1]
Signed-off-by: Vineet Gupta <[email protected]>
---
 tools/testing/selftests/bpf/network_helpers.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c
index db935a9d9fc1..3818cec354a0 100644
--- a/tools/testing/selftests/bpf/network_helpers.c
+++ b/tools/testing/selftests/bpf/network_helpers.c
@@ -1142,10 +1142,13 @@ static void encode_test_name(char *buf, size_t len, const char *test_name, const
 		snprintf(buf, len, "%s__%s", test_name, subtest_name);
 	else
 		snprintf(buf, len, "%s", test_name);
-	while ((p = strchr(buf, '/')))
-		*p = '_';
-	while ((p = strchr(buf, ' ')))
-		*p = '_';
+	/* Test names are free form, so replace anything that is awkward in a
+	 * file name. Besides the path separator, this covers the characters
+	 * rejected by CI systems collecting these logs as artifacts.
+	 */
+	for (p = buf; *p; p++)
+		if (strchr("/ \":<>|*?\r\n", *p))
+			*p = '_';
 }
 
 #define PCAP_DIR "/tmp/tmon_pcap"
-- 
2.55.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.