diff options
Diffstat (limited to 'src/fcopy/main.c')
-rw-r--r-- | src/fcopy/main.c | 33 |
1 files changed, 12 insertions, 21 deletions
diff --git a/src/fcopy/main.c b/src/fcopy/main.c index 67237b4ea..e65501d6d 100644 --- a/src/fcopy/main.c +++ b/src/fcopy/main.c | |||
@@ -23,7 +23,6 @@ | |||
23 | #include <ftw.h> | 23 | #include <ftw.h> |
24 | #include <errno.h> | 24 | #include <errno.h> |
25 | #include <pwd.h> | 25 | #include <pwd.h> |
26 | #include <sys/prctl.h> | ||
27 | 26 | ||
28 | #if HAVE_SELINUX | 27 | #if HAVE_SELINUX |
29 | #include <sys/stat.h> | 28 | #include <sys/stat.h> |
@@ -112,7 +111,7 @@ static void copy_file(const char *srcname, const char *destname, mode_t mode, ui | |||
112 | } | 111 | } |
113 | 112 | ||
114 | // open destination | 113 | // open destination |
115 | int dst = open(destname, O_CREAT|O_WRONLY|O_TRUNC, 0755); | 114 | int dst = open(destname, O_CREAT|O_WRONLY|O_TRUNC, S_IRUSR | S_IWUSR); |
116 | if (dst < 0) { | 115 | if (dst < 0) { |
117 | if (!arg_quiet) | 116 | if (!arg_quiet) |
118 | fprintf(stderr, "Warning fcopy: cannot open %s, file not copied\n", destname); | 117 | fprintf(stderr, "Warning fcopy: cannot open %s, file not copied\n", destname); |
@@ -133,7 +132,8 @@ static void copy_file(const char *srcname, const char *destname, mode_t mode, ui | |||
133 | done += rv; | 132 | done += rv; |
134 | } | 133 | } |
135 | } | 134 | } |
136 | fflush(0); | 135 | if (len < 0) |
136 | goto errexit; | ||
137 | 137 | ||
138 | if (fchown(dst, uid, gid) == -1) | 138 | if (fchown(dst, uid, gid) == -1) |
139 | goto errexit; | 139 | goto errexit; |
@@ -180,7 +180,7 @@ void copy_link(const char *target, const char *linkpath, mode_t mode, uid_t uid, | |||
180 | 180 | ||
181 | // if the link is already there, don't create it | 181 | // if the link is already there, don't create it |
182 | struct stat s; | 182 | struct stat s; |
183 | if (stat(linkpath, &s) == 0) | 183 | if (lstat(linkpath, &s) == 0) |
184 | return; | 184 | return; |
185 | 185 | ||
186 | char *rp = realpath(target, NULL); | 186 | char *rp = realpath(target, NULL); |
@@ -412,30 +412,21 @@ int main(int argc, char **argv) { | |||
412 | exit(1); | 412 | exit(1); |
413 | } | 413 | } |
414 | 414 | ||
415 | #ifdef WARN_DUMPABLE | 415 | warn_dumpable(); |
416 | if (prctl(PR_GET_DUMPABLE, 0, 0, 0, 0) == 1 && getuid()) | ||
417 | fprintf(stderr, "Error fcopy: I am dumpable\n"); | ||
418 | #endif | ||
419 | |||
420 | // trim trailing chars | ||
421 | if (src[strlen(src) - 1] == '/') | ||
422 | src[strlen(src) - 1] = '\0'; | ||
423 | if (dest[strlen(dest) - 1] == '/') | ||
424 | dest[strlen(dest) - 1] = '\0'; | ||
425 | 416 | ||
426 | // check the two files; remove ending / | 417 | // check the two files; remove ending / |
427 | int len = strlen(src); | 418 | size_t len = strlen(src); |
428 | if (src[len - 1] == '/') | 419 | while (len > 1 && src[len - 1] == '/') |
429 | src[len - 1] = '\0'; | 420 | src[--len] = '\0'; |
430 | if (strcspn(src, "\\*&!?\"'<>%^(){}[];,") != (size_t)len) { | 421 | if (strcspn(src, "\\*&!?\"'<>%^(){}[];,") != len) { |
431 | fprintf(stderr, "Error fcopy: invalid source file name %s\n", src); | 422 | fprintf(stderr, "Error fcopy: invalid source file name %s\n", src); |
432 | exit(1); | 423 | exit(1); |
433 | } | 424 | } |
434 | 425 | ||
435 | len = strlen(dest); | 426 | len = strlen(dest); |
436 | if (dest[len - 1] == '/') | 427 | while (len > 1 && dest[len - 1] == '/') |
437 | dest[len - 1] = '\0'; | 428 | dest[--len] = '\0'; |
438 | if (strcspn(dest, "\\*&!?\"'<>%^(){}[];,~") != (size_t)len) { | 429 | if (strcspn(dest, "\\*&!?\"'<>%^(){}[];,~") != len) { |
439 | fprintf(stderr, "Error fcopy: invalid dest file name %s\n", dest); | 430 | fprintf(stderr, "Error fcopy: invalid dest file name %s\n", dest); |
440 | exit(1); | 431 | exit(1); |
441 | } | 432 | } |