diff mbox series

[7/7] iw: fix fp handling inside handle_vendor

Message ID 20190517192956.18372-8-john@phrozen.org (mailing list archive)
State Accepted
Delegated to: Johannes Berg
Headers show
Series iw: various bug fixes | expand

Commit Message

John Crispin May 17, 2019, 7:29 p.m. UTC
The fp can leak and should not be closed if we do i/o redirection.

Signed-off-by: John Crispin <john@phrozen.org>
---
 vendor.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/vendor.c b/vendor.c
index 860cd48..d203d85 100644
--- a/vendor.c
+++ b/vendor.c
@@ -107,7 +107,8 @@  static int handle_vendor(struct nl80211_state *state,
 
 	if (file) {
 		count = read_file(file, buf, sizeof(buf));
-		fclose(file);
+		if (file != stdin)
+			fclose(file);
 	} else
 		count = read_hex(argc - 2, &argv[2], buf, sizeof(buf));
 
@@ -120,6 +121,8 @@  static int handle_vendor(struct nl80211_state *state,
 	return 0;
 
 nla_put_failure:
+	if (file && file != stdin)
+		fclose(file);
 	return -ENOBUFS;
 }