From e70631a5463f7dcb7ad70a0f92040c2d59ad947a Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Sun, 17 Jul 2022 22:36:55 -0500 Subject: [PATCH] Bugfix: The copy operation doesn't work properly with trailing slashes. The generated path might not be valid when a trailing slash is supplied on the source or the destination. Increase the static array size to accommodate at least 2 added separators. Only add the separators if one does not already exist. This does not attempt to clean up the code if there are multiple separators beyond the first. (That is to say "copy a/// b///" will not become "copy a/ b/".) --- level_3/fake/c/private-make-operate_process_type.c | 41 ++++++++++++++++++++-- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/level_3/fake/c/private-make-operate_process_type.c b/level_3/fake/c/private-make-operate_process_type.c index f16818a..615001a 100644 --- a/level_3/fake/c/private-make-operate_process_type.c +++ b/level_3/fake/c/private-make-operate_process_type.c @@ -65,7 +65,7 @@ extern "C" { for (; i < total; ++i) { - destination.used = data_make->cache_arguments.array[total].used; + destination.used = data_make->cache_arguments.array[total].used + 1; if (existing) { destination.used += data_make->cache_arguments.array[i].used + 1; @@ -74,12 +74,47 @@ extern "C" { f_char_t destination_string[destination.used + 1]; destination.string = destination_string; destination_string[destination.used] = 0; + destination_string[destination.used - 1] = 0; + + if (existing) { + destination_string[destination.used - 2] = 0; + } memcpy(destination_string, data_make->cache_arguments.array[total].string, sizeof(f_char_t) * data_make->cache_arguments.array[total].used); if (existing) { - memcpy(destination_string + data_make->cache_arguments.array[total].used + 1, data_make->cache_arguments.array[i].string, sizeof(f_char_t) * data_make->cache_arguments.array[i].used); - destination_string[data_make->cache_arguments.array[total].used] = f_path_separator_s.string[0]; + if (destination_string[data_make->cache_arguments.array[total].used - 1] == f_path_separator_s.string[0]) { + memcpy(destination_string + data_make->cache_arguments.array[total].used, data_make->cache_arguments.array[i].string, sizeof(f_char_t) * data_make->cache_arguments.array[i].used); + + if (data_make->cache_arguments.array[i].string[data_make->cache_arguments.array[i].used - 1] == f_path_separator_s.string[0]) { + destination.used -= 2; + } + else { + destination_string[data_make->cache_arguments.array[total].used + data_make->cache_arguments.array[i].used] = f_path_separator_s.string[0]; + + --destination.used; + } + } + else { + memcpy(destination_string + data_make->cache_arguments.array[total].used + 1, data_make->cache_arguments.array[i].string, sizeof(f_char_t) * data_make->cache_arguments.array[i].used); + + destination_string[data_make->cache_arguments.array[total].used] = f_path_separator_s.string[0]; + + if (data_make->cache_arguments.array[i].string[data_make->cache_arguments.array[i].used - 1] == f_path_separator_s.string[0]) { + --destination.used; + } + else { + destination_string[data_make->cache_arguments.array[total].used + 1 + data_make->cache_arguments.array[i].used] = f_path_separator_s.string[0]; + } + } + } + else { + if (destination_string[data_make->cache_arguments.array[total].used - 1] == f_path_separator_s.string[0]) { + --destination.used; + } + else { + destination_string[data_make->cache_arguments.array[total].used] = f_path_separator_s.string[0]; + } } status_file = f_directory_is(data_make->cache_arguments.array[i]); -- 1.8.3.1