summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko2018-09-03 10:25:29 +0200
committerDenys Vlasenko2018-09-03 10:25:29 +0200
commit3060992ec94722b4f8f3711a1884270c81a6e5f5 (patch)
tree3cf8d86d4f93f86ba2626daa4ec24f5932567f16
parent22a99516206b33b7ae124d426319bab03d5c8309 (diff)
downloadbusybox-3060992ec94722b4f8f3711a1884270c81a6e5f5.zip
busybox-3060992ec94722b4f8f3711a1884270c81a6e5f5.tar.gz
libbb: fix use-after-free in copy_file
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--libbb/copy_file.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/libbb/copy_file.c b/libbb/copy_file.c
index 98bd4fe..2d6557c 100644
--- a/libbb/copy_file.c
+++ b/libbb/copy_file.c
@@ -388,14 +388,15 @@ int FAST_FUNC copy_file(const char *source, const char *dest, int flags)
char *lpath = xmalloc_readlink_or_warn(source);
if (lpath) {
int r = symlink(lpath, dest);
- free(lpath);
if (r < 0) {
/* shared message */
bb_perror_msg("can't create %slink '%s' to '%s'",
"sym", dest, lpath
);
+ free(lpath);
return -1;
}
+ free(lpath);
if (flags & FILEUTILS_PRESERVE_STATUS)
if (lchown(dest, source_stat.st_uid, source_stat.st_gid) < 0)
bb_perror_msg("can't preserve %s of '%s'", "ownership", dest);