[PATCH 2/3] cp: Use posix_basename() on source argument

Sascha Hauer s.hauer at pengutronix.de
Wed Apr 19 01:06:11 PDT 2017


The GNU basename version does not work with strings which have a
trailing slash. Use posix_basename instead. With this cp -r
can properly work on source arguments which have a trailing slash,
i.e. "cp /dir1/ dst".

Reported-by: Peter Mamonov <pmamonov at gmail.com>
Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 commands/cp.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/commands/cp.c b/commands/cp.c
index 4f1c068dd6..54934dd64f 100644
--- a/commands/cp.c
+++ b/commands/cp.c
@@ -76,7 +76,8 @@ static int do_cp(int argc, char *argv[])
 
 	for (i = optind; i < argc - 1; i++) {
 		char *dst;
-		dst = concat_path_file(argv[argc - 1], basename(argv[i]));
+
+		dst = concat_path_file(argv[argc - 1], posix_basename(argv[i]));
 
 		if (recursive)
 			ret = copy_recursive(argv[i], dst);
-- 
2.11.0




More information about the barebox mailing list