diff options
author | Philip Guenther <guenther@cvs.openbsd.org> | 2015-08-24 00:11:00 +0000 |
---|---|---|
committer | Philip Guenther <guenther@cvs.openbsd.org> | 2015-08-24 00:11:00 +0000 |
commit | c24c964b7a243e372a449e7fde2341f2744ee05a (patch) | |
tree | 7087f894d4d2b39e0ea01c9fcc7a84177f58886c /bin | |
parent | 6add1229f8ea3ce1bdf5c90843f79060ab8c921c (diff) |
In fastcopy(), do the required malloc() before opening input or output file.
problem noted by Martijn van Duren (martijn987 (at) gmail.com)
Diffstat (limited to 'bin')
-rw-r--r-- | bin/mv/mv.c | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/bin/mv/mv.c b/bin/mv/mv.c index 2019a17ddab..4190f76e8be 100644 --- a/bin/mv/mv.c +++ b/bin/mv/mv.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mv.c,v 1.39 2015/05/03 19:44:59 guenther Exp $ */ +/* $OpenBSD: mv.c,v 1.40 2015/08/24 00:10:59 guenther Exp $ */ /* $NetBSD: mv.c,v 1.9 1995/03/21 09:06:52 cgd Exp $ */ /* @@ -260,6 +260,15 @@ fastcopy(char *from, char *to, struct stat *sbp) int nread, from_fd, to_fd; int badchown = 0, serrno = 0; + if (!blen) { + blen = sbp->st_blksize; + if ((bp = malloc(blen)) == NULL) { + warn(NULL); + blen = 0; + return (1); + } + } + if ((from_fd = open(from, O_RDONLY, 0)) < 0) { warn("%s", from); return (1); @@ -276,14 +285,6 @@ fastcopy(char *from, char *to, struct stat *sbp) } (void) fchmod(to_fd, sbp->st_mode & ~(S_ISUID|S_ISGID)); - if (!blen) { - blen = sbp->st_blksize; - if ((bp = malloc(blen)) == NULL) { - warn(NULL); - blen = 0; - return (1); - } - } while ((nread = read(from_fd, bp, blen)) > 0) if (write(to_fd, bp, nread) != nread) { warn("%s", to); |