From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 3/4] saveenv: Properly detect write errors
Date: Wed, 9 Apr 2014 09:39:25 +0200 [thread overview]
Message-ID: <1397029166-4412-4-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1397029166-4412-1-git-send-email-s.hauer@pengutronix.de>
The return value check of the write call is completely bogus. We
check if we have written at minimum sizeof(struct envfs_super) bytes
instead of all bytes. Properly check for all bytes written instead
and allow write to write less bytes than requested.
Do not use write_full because this file is compiled for userspace
aswell.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
common/environment.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/common/environment.c b/common/environment.c
index 9f4e098..bf813b4 100644
--- a/common/environment.c
+++ b/common/environment.c
@@ -201,11 +201,16 @@ int envfs_save(const char *filename, const char *dirname)
goto out1;
}
- if (write(envfd, buf, size + sizeof(struct envfs_super)) <
- sizeof(struct envfs_super)) {
- perror("write");
- ret = -1; /* FIXME */
- goto out;
+ size += sizeof(struct envfs_super);
+
+ while (size) {
+ ssize_t now = write(envfd, buf, size);
+ if (now < 0) {
+ ret = -errno;
+ goto out;
+ }
+
+ size -= now;
}
ret = 0;
--
1.9.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2014-04-09 7:39 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-09 7:39 Fix some longstanding environment bugs Sascha Hauer
2014-04-09 7:39 ` [PATCH 1/4] unlink_recursive: return negative error value Sascha Hauer
2014-04-09 7:39 ` [PATCH 2/4] loadenv: ignore -ENOENT when removing /env Sascha Hauer
2014-04-09 7:39 ` Sascha Hauer [this message]
2014-04-09 7:39 ` [PATCH 4/4] loadenv: detect truncated environment files Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1397029166-4412-4-git-send-email-s.hauer@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox