From 1e232a2ad2d353f7d125b9e993cd8f6152900937 Mon Sep 17 00:00:00 2001 From: nbd Date: Tue, 23 Sep 2008 16:12:40 +0000 Subject: firmware-utils: when using open with O_CREAT and O_WRONLY, also use O_TRUNC to ensure that overwritten files have the right size (fixes #3505) git-svn-id: svn://svn.openwrt.org/openwrt/trunk@12667 3c298f89-4303-0410-b956-a3cf2f4a3e73 --- tools/firmware-utils/src/motorola-bin.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tools/firmware-utils/src/motorola-bin.c') diff --git a/tools/firmware-utils/src/motorola-bin.c b/tools/firmware-utils/src/motorola-bin.c index 680249c00..58563add3 100644 --- a/tools/firmware-utils/src/motorola-bin.c +++ b/tools/firmware-utils/src/motorola-bin.c @@ -170,7 +170,7 @@ int main(int argc, char **argv) exit(3); } else { // all is well, write the file without the prefix - if ((fd = open(argv[3], O_CREAT|O_WRONLY,0644)) < 0 + if ((fd = open(argv[3], O_CREAT|O_WRONLY|O_TRUNC,0644)) < 0 || write(fd, trx + sizeof(struct motorola), len - sizeof(struct motorola)) != len - sizeof(struct motorola) || close(fd) < 0) { @@ -211,7 +211,7 @@ int main(int argc, char **argv) firmware->crc = htonl(crc32buf((unsigned char *)&firmware->flags, sizeof(firmware->flags) + len)); // write the firmware - if ((fd = open(argv[3], O_CREAT|O_WRONLY,0644)) < 0 + if ((fd = open(argv[3], O_CREAT|O_WRONLY|O_TRUNC,0644)) < 0 || write(fd, firmware, sizeof(struct motorola) + len) != sizeof(struct motorola) + len || close(fd) < 0) { -- cgit v1.2.3