Skip to content

Commit

Permalink
tools: mkenvimage: Fix reading from slow pipe
Browse files Browse the repository at this point in the history
It is perfectly fine for the read(2) syscall to return with less than
the requested number of bytes read (short read, see the "RETURN VALUE"
section of the man page). This typically happens with slow input
(keyboard, network) or with complex pipes.

So far mkenvimage expects the exact number of requested bytes to be
read, assuming an end-of-file condition otherwise. This wrong behaviour
can be easily shown with:
$ (echo "foo=bar"; sleep 1; echo "bar=baz") | mkenvimage -s 256 -o out -
The second line will be missing from the output.

Correct this by checking for any positive, non-zero return value.

This fixes a problem with a complex pipe in one of my scripts, where
the environment consist of two parts.

Signed-off-by: Andre Przywara <[email protected]>
Acked-by: Alexander Dahl <[email protected]>
  • Loading branch information
Andre-ARM authored and trini committed Jul 18, 2019
1 parent bdfc9e8 commit 40e7b3c
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions tools/mkenvimage.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,7 @@ int main(int argc, char **argv)
return EXIT_FAILURE;
}
filesize += readbytes;
} while (readbytes == readlen);

} while (readbytes > 0);
} else {
txt_filename = argv[optind];
txt_fd = open(txt_filename, O_RDONLY);
Expand Down

0 comments on commit 40e7b3c

Please sign in to comment.