From c24c964b7a243e372a449e7fde2341f2744ee05a Mon Sep 17 00:00:00 2001 From: Philip Guenther Date: Mon, 24 Aug 2015 00:11:00 +0000 Subject: In fastcopy(), do the required malloc() before opening input or output file. problem noted by Martijn van Duren (martijn987 (at) gmail.com) --- bin/mv/mv.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'bin') 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); -- cgit v1.2.3