From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 4/4] loadenv: detect truncated environment files
Date: Wed, 9 Apr 2014 09:39:26 +0200 [thread overview]
Message-ID: <1397029166-4412-5-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1397029166-4412-1-git-send-email-s.hauer@pengutronix.de>
Properly detect when an environment file is truncated. This can happen
when a previous saveenv failed because the environment partition is too
small.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
common/environment.c | 23 ++++++++++++++++++-----
1 file changed, 18 insertions(+), 5 deletions(-)
diff --git a/common/environment.c b/common/environment.c
index bf813b4..abd69c5 100644
--- a/common/environment.c
+++ b/common/environment.c
@@ -409,11 +409,24 @@ int envfs_load(const char *filename, const char *dir, unsigned flags)
goto out;
buf = xmalloc(size);
- ret = read(envfd, buf, size);
- if (ret < size) {
- perror("read");
- ret = -errno;
- goto out;
+
+ while (size) {
+ ssize_t now;
+
+ now = read(envfd, buf, size);
+ if (now < 0) {
+ perror("read");
+ ret = -errno;
+ goto out;
+ }
+
+ if (!now) {
+ printf("%s: premature end of file\n", filename);
+ ret = -EINVAL;
+ goto out;
+ }
+
+ size -= now;
}
ret = envfs_check_data(&super, buf, size);
--
1.9.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
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 ` [PATCH 3/4] saveenv: Properly detect write errors Sascha Hauer
2014-04-09 7:39 ` Sascha Hauer [this message]
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-5-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