Skip to content

Commit

Permalink
tools: mkenvimage: Fix possible segfault on stdin input
Browse files Browse the repository at this point in the history
The size of 'filebuf' was not increased as more and more bytes are read
from stdin, but 'filebuf' was always reallocated to the same fix size.
This works as long as only less bytes than the initial buffer size come
in, for more input this will segfault. (It actually does, I tested
that.) So for each loop cycle the buffer size has to be increased by the
number of bytes we want to read.

Signed-off-by: Alexander Dahl <[email protected]>
  • Loading branch information
LeSpocky authored and trini committed Apr 28, 2018
1 parent 3559028 commit c3b115f
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion tools/mkenvimage.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ int main(int argc, char **argv)
txt_fd = STDIN_FILENO;

do {
filebuf = realloc(filebuf, readlen);
filebuf = realloc(filebuf, filesize + readlen);
if (!filebuf) {
fprintf(stderr, "Can't realloc memory for the input file buffer\n");
return EXIT_FAILURE;
Expand Down

0 comments on commit c3b115f

Please sign in to comment.