summaryrefslogtreecommitdiff
path: root/nand-utils
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-01-24 23:01:57 +0100
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-02-09 22:13:18 +0100
commitb636250e211198210ab996671bccc2983300c6f5 (patch)
treeda1793fcd90dfd2b411afc1bc7cc2249b47c8e4f /nand-utils
parent11bc41c32cc933a141545be6a9729122ac436cfe (diff)
mtd-utils: Fix potential negative arguments passed to close(2)
Many tools open a file descriptor, close it a the end and have some form of error path in between that jumps to the end. In some cases, if opening the file fails the error path is taken and the utility ends up closing one or more invalid file descriptors. It's technically not a real issue but something that pretty much any static analysis tool barks at. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'nand-utils')
-rw-r--r--nand-utils/nanddump.c3
-rw-r--r--nand-utils/nandwrite.c3
2 files changed, 4 insertions, 2 deletions
diff --git a/nand-utils/nanddump.c b/nand-utils/nanddump.c
index 841ed67..62699e0 100644
--- a/nand-utils/nanddump.c
+++ b/nand-utils/nanddump.c
@@ -549,7 +549,8 @@ int main(int argc, char * const argv[])
closeall:
close(fd);
- close(ofd);
+ if (ofd > 0 && ofd != STDOUT_FILENO)
+ close(ofd);
free(oobbuf);
free(readbuf);
exit(EXIT_FAILURE);
diff --git a/nand-utils/nandwrite.c b/nand-utils/nandwrite.c
index 8f21593..e8a210c 100644
--- a/nand-utils/nandwrite.c
+++ b/nand-utils/nandwrite.c
@@ -605,7 +605,8 @@ int main(int argc, char * const argv[])
failed = false;
closeall:
- close(ifd);
+ if (ifd > 0 && ifd != STDIN_FILENO)
+ close(ifd);
libmtd_close(mtd_desc);
free(filebuf);
close(fd);