9
0
Fork 0

saveenv: Properly detect write errors

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>
This commit is contained in:
Sascha Hauer 2014-04-08 17:20:03 +02:00
parent 8d0b6dd410
commit aa49d86b2d
1 changed files with 14 additions and 6 deletions

View File

@ -167,7 +167,7 @@ int envfs_save(const char *filename, const char *dirname)
struct envfs_super *super;
int envfd, size, ret;
struct action_data data;
void *buf = NULL;
void *buf = NULL, *wbuf;
data.writep = NULL;
data.base = dirname;
@ -201,11 +201,19 @@ 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);
wbuf = buf;
while (size) {
ssize_t now = write(envfd, wbuf, size);
if (now < 0) {
ret = -errno;
goto out;
}
wbuf += now;
size -= now;
}
ret = 0;