From 10a13c64cc5ee3ff16caa77a7b809702cff38595 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Mon, 14 Feb 2022 20:04:35 -0500 Subject: Implement --all/-A * Apply filters to all environment variables --- lib/cleanpath.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'lib') diff --git a/lib/cleanpath.c b/lib/cleanpath.c index 91b399d..138251f 100644 --- a/lib/cleanpath.c +++ b/lib/cleanpath.c @@ -102,18 +102,24 @@ void cleanpath_filter(struct CleanPath *path, unsigned mode, const char *pattern char *cleanpath_read(struct CleanPath *path) { char *result; size_t result_len; + size_t part_count; result = calloc(path->data_len, sizeof(char)); if (result == NULL) { goto cleanpath_read__failure; } + for (part_count = 0; part_count < CLEANPATH_PART_MAX && path->part[part_count] != NULL; part_count++); + for (size_t i = 0; i < CLEANPATH_PART_MAX && path->part[i] != NULL; i++) { // Ignore filtered paths if (*path->part[i] == '\0') { continue; } strcat(result, path->part[i]); + if (part_count > 1 && i == 0) { + continue; + } strcat(result, path->sep); } -- cgit