From 490eabb0e16feb8bcd3562a7e3761c8945fd9757 Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Wed, 11 Jan 2017 09:09:54 -0800 Subject: [PATCH] Spi-hdlc-adapter: Check for invalid `fd` errors (#1129) This commit makes a change to `spi-hdlc-adapter` to check for any possible error case where either `sHdlcInputFd` or `sHdlcOutputFd` are invalid (e.g., `dup()` failures) before starting the main loop. --- tools/spi-hdlc-adapter/spi-hdlc-adapter.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tools/spi-hdlc-adapter/spi-hdlc-adapter.c b/tools/spi-hdlc-adapter/spi-hdlc-adapter.c index 2a0b58e06..7fcd841b6 100644 --- a/tools/spi-hdlc-adapter/spi-hdlc-adapter.c +++ b/tools/spi-hdlc-adapter/spi-hdlc-adapter.c @@ -1540,6 +1540,12 @@ int main(int argc, char *argv[]) goto bail; } + if ((sHdlcInputFd < 0) || (sHdlcOutputFd < 0)) + { + sRet = EXIT_FAILURE; + goto bail; + } + // Set up sHdlcInputFd for non-blocking I/O if (-1 == (i = fcntl(sHdlcInputFd, F_GETFL, 0))) {