[hackers] [ubase] [PATCH] dd: Avoid VLA based on user-specified value

From: Michael Forney <mforney_AT_mforney.org>
Date: Sun, 19 May 2019 11:41:52 -0700

---
 dd.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/dd.c b/dd.c
index 2dce98e..123cb47 100644
--- a/dd.c
+++ b/dd.c
_AT_@ -126,14 +126,16 @@ prepare_copy(struct dd_config *ddc, int *ifd, int *ofd)
 	}
 
 	if (lseek(*ifd, ddc->skip, SEEK_CUR) < 0) {
-		char buffer[ddc->bs];
+		char *buffer = emalloc(ddc->bs);
 		for (uint64_t i = 0; i < ddc->skip; i += ddc->bs) {
 			if (read(*ifd, &buffer, ddc->bs) < 0) {
 				errno = EINVAL;
 				close(*ifd);
+				free(buffer);
 				return -1;
 			}
 		}
+		free(buffer);
 	}
 	lseek(*ofd, ddc->seek, SEEK_CUR);
 	posix_fadvise(*ifd, ddc->skip, 0, POSIX_FADV_SEQUENTIAL);
-- 
2.20.1
Received on Sun May 19 2019 - 20:41:52 CEST

This archive was generated by hypermail 2.3.0 : Tue May 21 2019 - 17:00:27 CEST