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@xxxxxxxxxxxxxx> --- 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@xxxxxxxxxxxxxxxxxxx http://lists.infradead.org/mailman/listinfo/barebox