diff options
author | Felix Fietkau <nbd@openwrt.org> | 2008-09-23 16:12:40 +0000 |
---|---|---|
committer | Felix Fietkau <nbd@openwrt.org> | 2008-09-23 16:12:40 +0000 |
commit | 216c6cd8a9cc2afff60d833dd462c3801a3e1bb2 (patch) | |
tree | 5d763021ccb927a66bb4ca6f154689a3a47cb90c /tools/firmware-utils/src/motorola-bin.c | |
parent | c3ae8337f4aa4a882b717ba73e8a25a70ddf9f43 (diff) | |
download | upstream-216c6cd8a9cc2afff60d833dd462c3801a3e1bb2.tar.gz upstream-216c6cd8a9cc2afff60d833dd462c3801a3e1bb2.tar.bz2 upstream-216c6cd8a9cc2afff60d833dd462c3801a3e1bb2.zip |
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)
SVN-Revision: 12667
Diffstat (limited to 'tools/firmware-utils/src/motorola-bin.c')
-rw-r--r-- | tools/firmware-utils/src/motorola-bin.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/tools/firmware-utils/src/motorola-bin.c b/tools/firmware-utils/src/motorola-bin.c index 680249c007..58563add32 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) { |